class BackgroundPath:Image
{
public event PropertyChangedEventHandler PropertyChanged;
static BackgroundPath()
{
BindSourceProperty =
DependencyProperty.Register("BindSource",
typeof(BitmapImage),
typeof(BackgroundPath),
new PropertyMetadata(new BitmapImage(new Uri(PathShow.ImageSelected)), OnBitmapImageChanged));
}
public BitmapImage BindSource
{
get
{ return (BitmapImage)GetValue(BindSourceProperty);}
set
{ SetValue(BindSourceProperty, value);}
}
public static DependencyProperty BindSourceProperty { private set; get; }
static void OnBitmapImageChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
(obj as BackgroundPath).OnBitmapImageChanged(args);
}
void OnBitmapImageChanged(DependencyPropertyChangedEventArgs args)
{
if (args.Property == BindSourceProperty)
BindSource = (BitmapImage)args.NewValue;
}
}
Binding bind = new Binding()
{
Source = new BackgroundPath(),
Path = new PropertyPath("BindSource")
};
faceImge.SetBinding(Image.SourceProperty,bind);