0

I try this code bellow, but without any result, could you please tell my why? I have a rectangle shape in WPF C#, which’s filled with an imagebrush as you see, and I used inline if, but it doesn’t worked as I planed…

Rec1.Fill = Rec1.Fill == (new ImageBrush(new BitmapImage(new Uri(@”C:\1.png”, UriKind.Relative)))
    ? (new ImageBrush(new BitmapImage(new Uri(@”C:\2.png”, UriKind.Relative)))
    : (new ImageBrush(new BitmapImage(new Uri(@”C:\1.png”, UriKind.Relative)));

Note that: Rec1 is my Rectangle; ImageBrush source is 1.png and I want it to be changed to 2.png That’s all I want… but it doesn’t worked.. could you please tell me why?

Venkatachalam
  • 16,288
  • 9
  • 49
  • 77
Aso Salih
  • 1
  • 1
  • The result of the comparison `Rec1.Fill == new ImageBrush(...)` is always false, because you are comparing against a new object. Keep both ImageBrushes as class members and write something like: `Rec1.Fill = Rec1.Fill == ib1 ? ib2 : ib1;` – Clemens Apr 26 '20 at 07:31
  • Also be aware that `C:\1.png` is not a relative path, so `UriKind.Relative` is wrong. – Clemens Apr 26 '20 at 07:33

0 Answers0