Tutorial :How do I get the actual value of a DependancyProperty?



Question:

I have a small UserControl and it needs to know the Background Brush of the control on which it's being rendered.

However, if I look in the Background property of the UserControl it comes back null.

If I call GetValue(UserControl.BackgroundProperty) it also returns null even though up the Visual tree it is definitely being set.

Seems like I must be missing something pretty obvious as it's can't be that hard to figure out the background colour of a control.


Solution:1

It seems to me that your UserControl does not have a background color defined - null means transparent, which is why the parent control's background is visible at all.

It is still the background color of the parent control - the fact that your control does not have its own background color does not mean that it takes the color from the parent control. The "background" of your control will simply show whatever is behind your control.


Solution:2

The background property is not inherited from the parent, you have to set it yourself.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »