I have an image control on a Window in my WPF project
XAML:
<Image
Source="{Binding NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True}"
Binding.SourceUpdated="bgMovie_SourceUpdated"
Binding.TargetUpdated="bgMovie_TargetUpdated" />
In code I am changing the source of the image
C#:
myImage = new BitmapImage();
myImage.BeginInit();
myImage.UriSource = new Uri(path);
myImage.EndInit();
this.bgMovie.Source = myImage;
But the bgMovie_SourceUpdated event is never triggered.
Can anyone shed some light on what I’m doing wrong?
By assiging a value directly to the
Sourceproperty, you’re “unbinding” it… YourImagecontrol is not databound anymore, it just has a local value.In 4.0 you could use the
SetCurrentValuemethod:Unfortunately this method isn’t available in 3.5, and there is no easy alternative…
Anyway, what are you trying to do exactly ? What is the point of binding the
Sourceproperty if you’re setting it manually anyway ? If you want to detect when theSourceproperty changes, you can use theDependencyPropertyDescriptor.AddValueChangedmethod: