class BackgroundPath: INotifyPropertyChanged { BitmapImage bindSource = new BitmapImage(new Uri(PathShow.ImageSelected)); //预设值 public event PropertyChangedEventHandler PropertyChanged; public BitmapImage BindSource { set { SetProperty(ref bindSource, value, "BindSource");} get { return bindSource;} } protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName]string propertyName = null) { if (object.Equals(storage, value)) return false; storage = value; OnPropertyChanged(propertyName); return true; } protected void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } }
Binding bind = new Binding()
{
Source = new BackgroundPath(),
Path = new PropertyPath("BindSource")
};
faceImge.SetBinding(Image.SourceProperty,bind);