mrfangzheng

Hope and fear are useless. Be confident, and always be prepared for the worst.
  首页  :: 新随笔  :: 联系 :: 管理

Dependency property changed example

Posted on 2008-08-01 16:19  mrfangzheng  阅读(177)  评论(0编辑  收藏  举报
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; }