I'm trying to change an image source by clicking on something.
my .xaml
<Canvas Name="img_Canvas" Grid.IsSharedSizeScope="True">
<Image Source="{Binding ImageType_Source}" Name="autoImage" Margin="5"/>
my .cs
private string _ImageType_Source;
public string ImageType_Source
{
get { return _ImageType_Source; }
set {
_ImageType_Source = value;
OnPropertyChanged("ImageType_Source");
}
}
public exImage()
{
InitializeComponent();
DataContext = this;
So when I click on e.g Ellipse, I want to change the image.
private void Ellipse_MouseDown(object sender, MouseButtonEventArgs e)
{
ImageType_Source = "/ANKE_Test;component/imagesFolder/Bild_Getriebe.jpg";
string test = autoImage.Source.ToString();
After changing the source the PropertyChangedEvent is fired with PropertyChanged = null but with the new source. Unfortunately the source in the image is still the old one and is not changing.
PropertyChanged == nullthat implies that nothing is listening to the event so the UI can't react and change. Does your .cs implementINotifyPropertyChanged?if (this.PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(name));rather thanOnPropertyChanged(name);. You're not firing the event.