I have a dependency property (Foreground) on a custom control which is inheriting from Control. When I am loading the control, I want to see if the user has set the dependency property or if it is using its default value before I set the value for them. The problem is a bit more complicated then that, here it is:
The control is in a custom control library that a user adds to their project. When they are setting up their project, I have the ability for them to add a line to their app.xaml file with a given x:key that contains the settings that I read while setting the default values for my controls. However, if they set the value either in code, or in xaml, I do not want to set the value with this global value. Here are a few cases to help visualize what I'm talking about:
The user creates a control from my library and puts it on their page. They then set the foreground to green. I want the value of the foreground to be green for that control.
The user adds a special line to their app.xaml that states they want all controls of a particular kind to have a foreground of red. I want the value of the foreground of all controls of that kind to be red.
The user adds a special line to their app.xaml that states they want all controls of a particular kind to have a foreground of red. They then set the value of the foreground of a single control (in xaml) to yellow. I want the value of the foreground of all controls of that kind to be red, except for the one they otherwise specified to be yellow.
When loading the control, I want to read the dependency property to see if they have set the value, or if it is the default value which is defined in the style. If it is the default value, I want to then read their special line out of the app.xaml file and set the fore ground to that color.