Instead of checking the Fill file name, you can change the Rectangle Tag property (or create your own UserControl ). Then, for example, you can do this:
<Rectangle Height="auto" Width="auto" x:Name="Honey" ManipulationStarted="Honey_Started" Tag="image1"> <Rectangle.Fill> <ImageBrush ImageSource="image100.jpg" /> </Rectangle.Fill> </Rectangle>
I added Tag="image1" as an attribute in the Rectangle . Then you can access this in code and check.
private void Honey_Started(object sender, ManipulationStartedEventArgs e) { if (Honey.Tag.ToString() == "image1") { ImageBrush ib = new ImageBrush(); BitmapImage bImage = new BitmapImage(new Uri("900image.jpg",UriKind.Relative)); ib.ImageSource = bImage; Honey.Tag = "900image.jpg"; Honey.Fill = ib; } }
There are other methods. All I did in the Honey_Started event was to create a new ImageBrush code, assign it an image ( 900image.jpg ), and then set ImageBrush to Fill for the rectangle.
An alternative method could be to store two ImageBrushes as a class level variable and use them to compare values.
BitmapImage biImage100 = new BitmapImage(new Uri("/Jar/image100.jpg",UriKind.Relative)); ImageBrush ibImage100 = new ImageBrush() { ImageSource = biImage100 }; ImageBrush ib900image = new ImageBrush() { }; private void Honey_Started(object sender, ManipulationStartedEventArgs e) { if (Honey.Fill == ibImage100) { Honey.Fill = ib900image; } }
source share