WpfExpressionBlendTheme icon indicating copy to clipboard operation
WpfExpressionBlendTheme copied to clipboard

Cannot change control background color

Open mpoelzl opened this issue 6 years ago • 3 comments
trafficstars

Hello! When using the blend theme I am unable to change the background color for individual controls. For example If I explicitly set a textbox Background to Red in xaml, the control will be shown in red in the editor preview but at runtime the textbox has the standard background color.

I did a bit of testing and the color that's actually being used is the background color of the ScrollViewer. So if I go and change the scrollviewer style in the Styles.xaml file then that color will be shown.

Any ideas why this is and how we can change it so that the background color can be overridden?

Thanks!

Mike

mpoelzl avatar Mar 18 '19 12:03 mpoelzl

Ok, so after a bit of experimenting it appears to work if I add the 'Background' property to the ScrollViewer in the TextBox style's control template and set to 'TemplateBinding Background'.

Is this the right way to go about it (other controls would also need this)?

mpoelzl avatar Mar 18 '19 12:03 mpoelzl

It should be correct, however I'm not 100% sure because the code was written long time ago.

You can confirm that by generating a default WPF template and check the original approach.

If you want to update the background color everywhere, then you probably should do it like that:

<SolidColorBrush x:Key="ScrollViewerBackground" Color=“Red” />

DanPristupov avatar Mar 18 '19 13:03 DanPristupov

In fact I think it's easier to just get rid of the Background setter in the scrollviewer style.

mpoelzl avatar Mar 18 '19 17:03 mpoelzl