代码改变世界

WPF技巧(3)监测属性变更

2010-05-07 14:57  Clingingboy  阅读(1018)  评论(0编辑  收藏  举报
public Window1()
{
    InitializeComponent();
    this.TargetUpdated += new EventHandler<DataTransferEventArgs>(Window1_TargetUpdated);
    this.SourceUpdated += new EventHandler<DataTransferEventArgs>(Window1_SourceUpdated);
}
static Window1()
{
    Window.WidthProperty.OverrideMetadata(typeof(Window1), new FrameworkPropertyMetadata(new PropertyChangedCallback(WidthPropertyChangedCallback)));
}

public static void WidthPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    Console.WriteLine(e.NewValue);
}

void Window1_TargetUpdated(object sender, DataTransferEventArgs e)
{
    
}

void Window1_SourceUpdated(object sender, DataTransferEventArgs e)
{
    
}

protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
    base.OnPropertyChanged(e);
}