mardi 7 août 2018

Define an image source using if c# wpf

My question is, how can I make sure that, an image's source is the same that I want to. Here's the example, that I did:

 private void btn_color_green_click(object sender, RoutedEventArgs e)
    {
        if (color_green.Source.ToString() == (@"/img/point_color_green_selected.png")) { Environment.Exit(0); }
        if (color_red.Source.ToString() == (@"/img/point_color_red_selected.png"))
        {
            color_red.Source = new BitmapImage(new Uri(@"/img/point_color_red.png", UriKind.Relative));
            color_green.Source = new BitmapImage(new Uri(@"/img/point_color_green_selected.png", UriKind.Relative));
        }
        if (color_blue.Source.ToString() == (@"/img/point_color_blue_selected.png"))
        {
            color_blue.Source = new BitmapImage(new Uri(@"/img/point_color_blue.png", UriKind.Relative));
            color_green.Source = new BitmapImage(new Uri(@"/img/point_color_green_selected.png", UriKind.Relative));
        }
        if (color_yellow.Source.ToString() == (@"/img/point_color_yellow_selected.png"))
        {
            color_yellow.Source = new BitmapImage(new Uri(@"/img/point_color_yellow.png", UriKind.Relative));
            color_green.Source = new BitmapImage(new Uri(@"/img/point_color_green_selected.png", UriKind.Relative));
        }
        if (color_purple.Source.ToString() == (@"/img/point_color_purple_selected.png"))
        {
            color_purple.Source = new BitmapImage(new Uri(@"/img/point_color_purple.png", UriKind.Relative));
            color_green.Source = new BitmapImage(new Uri(@"/img/point_color_green_selected.png", UriKind.Relative));
        }
    }

If I click on the "btn_color_green_click", it doesn't even quit from the program, so the problem is probably with the "if" part.

Any idea?

Aucun commentaire:

Enregistrer un commentaire