Dependency property changed example

public double ScaleFactor
{
    get { return (double)GetValue(ScaleFactorProperty); }
    set { SetValue(ScaleFactorProperty, value); }
}

// Using a DependencyProperty as the backing store for ScaleFactor.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty ScaleFactorProperty =
    DependencyProperty.Register("ScaleFactor", typeof(double), typeof(ToolBlockControl), 
new UIPropertyMetadata(1.0,new PropertyChangedCallback(ScaleFactorChangedCallBack))); private static void ScaleFactorChangedCallBack(DependencyObject obj, DependencyPropertyChangedEventArgs args) { var toolBlockControl = obj as ToolBlockControl; double scaleFactor = (double)args.NewValue; toolBlockControl.Width = toolBlockControl.mActualWidth * scaleFactor; toolBlockControl.Height = toolBlockControl.mActualHeight * scaleFactor; }
原文地址:https://www.cnblogs.com/mrfangzheng/p/1258294.html