Why is ImageSource being called twice in WPF?

My app changes photos with the click of a button. However, when I watch it with a breakpoint, the ImageSource property is referenced twice each time. Other properties are mentioned only once.

Why is ImageSource "getting" working twice?

Specifically, this line is executed two times, back to back, right after PropertyChanged()

:
 get { return picture; }

This is how I update the image in the GUI:

public class ApplicationState : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private ImageSource picture;

    public ImageSource Picture
    {
        get { return picture; }
        set
        {
            picture = value;
            NotifyPropertyChanged("Picture");
        }
    }

    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

      

This is the XAML for the image:
<Image Source="{Binding Path=Picture}"/>

And changing the image is triggered with:
Picture = Convert(picturePath);

Am I missing something? Why would this ever work twice backwards?

Edit: Microsoft explains some of the reasons in this post .

+3


source to share





All Articles