tags:

views:

57

answers:

2

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.

+2  A: 

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.

Sander
Nope I defo set it to Gray
Jan Bannister
+1  A: 

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

Nir