Why doesn't the SourceUpdated event fire for my Image Control in WPF?

I have an image control in a window in a WPF project

XAML:

<Image 
  Source="{Binding NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}" 
  Binding.SourceUpdated="bgMovie_SourceUpdated" 
  Binding.TargetUpdated="bgMovie_TargetUpdated" />

In the code, I change the image source

WITH#:

myImage = new BitmapImage();
myImage.BeginInit();
myImage.UriSource = new Uri(path);
myImage.EndInit();
this.bgMovie.Source = myImage;

But the bgMovie_SourceUpdated event never fires.

Can anyone shed light on what I'm doing wrong?

+3
source share
3 answers

By recognizing the value directly to the property Source, you "untie" it ... Your control is Imageno longer bound to the database, it has a local value.

In 4.0 you can use the method SetCurrentValue:

this.bgMovie.SetCurrentValue(Image.SourceProperty, myImage);

Unfortunately, this method is not available in 3.5, and there is no simple alternative ...

, ? Source, ? , Source, DependencyPropertyDescriptor.AddValueChanged:

var prop = DependencyPropertyDescriptor.FromProperty(Image.SourceProperty, typeof(Image));
prop.AddValueChanged(this.bgMovie, SourceChangedHandler);
...

void SourceChangedHandler(object sender, EventArgs e)
{

}
+6

Source XAML.

, ( ) . .

XAML:

<Image Name="bgMovie" 
       Source="{Binding MovieImageSource, 
                        NotifyOnSourceUpdated=True, 
                        NotifyOnTargetUpdated=True}"
       Binding.SourceUpdated="bgMovie_SourceUpdated" 
       Binding.TargetUpdated="bgMovie_TargetUpdated" />

#:

    public ImageSource MovieImageSource
    {
        get { return mMovieImageSource; }
        // Set property sets the property and implements INotifyPropertyChanged
        set { SetProperty("MovieImageSource", ref mMovieImageSource, value); }
    }

   void SetMovieSource(string path)
   {
        myImage = new BitmapImage();
        myImage.BeginInit();
        myImage.UriSource = new Uri(path);
        myImage.EndInit();
        this.MovieImageSource = myImage;
   }
+3

, :

https://msdn.microsoft.com/en-us/library/system.windows.data.binding.targetupdated(v=vs.100).aspx , NotifyOnTargetUpdated ( NotifyOnSourceUpdated):

Text="{Binding Path=Rent, Mode=OneWay, NotifyOnTargetUpdated=True}"

, , EventTrigger .

0

Source: https://habr.com/ru/post/1766826/


All Articles