HighTechTalks DotNet Forums  

[WPF Property Changes] What is the correct way to hook into a WPFproperty change.

Dotnet Framework microsoft.public.dotnet.framework


Discuss [WPF Property Changes] What is the correct way to hook into a WPFproperty change. in the Dotnet Framework forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Alan Samet
 
Posts: n/a

Default [WPF Property Changes] What is the correct way to hook into a WPFproperty change. - 12-27-2007 , 01:14 PM






In the "old days" of Windows Forms, if you had a control with, say, a
DataSource property and wanted to perform some action when the
property changed, you would simply put your logic right into the
property accessor. Now, with WPF and DependencyProperties, it doesn't
seem "right" to do this anymore. The only solution that seems to work
for me is as follows, but I'm not sure that it's right. Could somebody
that really understands what's going on here provide some
enlightenment?

//Constructor
pubic Test()
{
DependencyPropertyDescriptor.FromProperty(MyProper tyProperty,
typeof(Test)).AddValueChanged(this, delegate(object sender, EventArgs
e){/*Logic that you would previously have in your set accessor goes
here*/});
}

public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(Test),
typeof(string));
public string MyProperty
{
get {return (string)GetValue(MyPropertyProperty);}
set {SetValue(MyPropertyProperty, value);}
}

-Alan

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.