Dependency Properties Made Easy
Join the DZone community and get the full member experience.
Join For FreeOk, so I found that for some reason I thought I did a post on this before
and I couldn't find it. So I thought I would make a new post as simple
as possible. Here is a simple dp:
You'll note that this has a changed handler but otherwise is like the first version. and that is pretty much it. :)
public readonly DependencyProperty ResistanceProperty = DependencyProperty.Register("Resistance", typeof(double), typeof(AnimatingPanelBase), null); public double Resistance { get { return (double)GetValue(ResistanceProperty); } set { SetValue(ResistanceProperty, value); } }Nice and simple right? why bother you ask, well the biggest issue is that if you want to animate properties of a custom control of some kind using data binding and what that change to filter into the UI of some control. Otherwise I try to avoid DP's as much as possible. So if you need todo some mucking around in your control after the DP value has changed then do this:
public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(double), typeof(Dial), new PropertyMetadata(new PropertyChangedCallback(OnMinimumChanged))); public double Minimum { get { return (double)GetValue(MinimumProperty); } set { SetValue(MinimumProperty, value); } } private static void OnMinimumChanged(DependencyObject DpObj, DependencyPropertyChangedEventArgs e) { // some code : }
You'll note that this has a changed handler but otherwise is like the first version. and that is pretty much it. :)
Property (programming)
Dependency
Published at DZone with permission of David Kelley. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments