Alex Rivera | Logout

When to use Dependency Properties

Asked 2010-11-05T07:31:53.380
14

I sometimes think I maybe using Dependency Properties unnecessarily. When do I need to use it? When I have a property that dependes on other properties? Say I have a Color property that I want it to be dependent on properties Hue, Saturation, Luminosity do I use a dependency property? Or what do I use? I controls thats bound to Color to update when properties Hue, Saturation, Luminosity are changed.

for now what I did was

public byte Hue {
    get { return _hue; }
    set
    {
        if (_hue == value)
            return;
        _hue = value;
        NotifyPropertyChanged("Hue");
        NotifyPropertyChanged("Color"); // to update controls bound to color
    }
}

But I think this is not the right way of doing things? If I have more properties that affect color, I will have 1 extra line in all those properties?

Edit
Report

1 Answer

2

Another use of dependency properties is with navigation journal. Custom dependency properties on a Page with Juornal flag in the meta-data are included in the state that WPF saves for the page.

answered 2012-10-24T09:24:32.973

Your Answer