wpf 依赖属性

public static readonly DependencyProperty AquariumGraphicProperty = DependencyProperty.Register(
  "AquariumGraphic",
  typeof(Uri),
  typeof(AquariumObject),
  new PropertyMetadata(null,
      new PropertyChangedCallback(OnUriChanged)
  )
);
public Uri AquariumGraphic
{
    get { return (Uri)GetValue(AquariumGraphicProperty); }
    set { SetValue(AquariumGraphicProperty, value); }
}


private static void OnUriChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    Shape sh = (Shape)d;
    ImageBrush ib = new ImageBrush();
    ib.ImageSource = new BitmapImage(e.NewValue as Uri);
    sh.Fill = ib;
}
原文地址:https://www.cnblogs.com/btbear/p/3383631.html