Jan Bannister
Jan Bannister

Reputation: 4999

How do I get the actual value of a DependancyProperty?

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.

Upvotes: 1

Views: 112

Answers (2)

Nir
Nir

Reputation: 29594

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

Upvotes: 1

Sander
Sander

Reputation: 26354

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.

Upvotes: 2

Related Questions