I am new to WPF and C#, I try to implement the following feature, but failed after a lot of attempts. Can anyone help me out?
I have an image control:
<Image Grid.Row="1" x:Name="ImageEditor" Stretch="Fill" StretchDirection="Both"/>
I want to bind the source of this image control to a static property of another class (ImageHandler)
class ImageHandler
{
public static BitmapImage ImageToDisplay { get; set; }
public ImageHandler(){}
.... //other codes
}
So whenever I do something in the ImageHandler class, and update the ImageToDisplay property, my image control will display the new image.
I have try several methods, but none of them achieved this goal. The following shows one of my failed attempts.
<Window.Resources>
<local:ImageHandler x:Key="ImageHandler"></local:ImageHandler>
</Window.Resources>
<Image Grid.Row="1" x:Name="ImageEditor" Stretch="Fill" StretchDirection="Both"
Source="{Binding Source={StaticResource ResourceKey=ImageHandler},
Path=ImageToDisplay,Mode=TwoWay}">
</Image>
You have to implement either
INotifyPropertyChangedinImageHandlerFor dependency property :
However, to implement it, I had to remove the
staticattribute.