Cannot bind to resource in my style wpf
this is my style:
<Style x:Key="someStyle" TargetType="{x:Type Border}">
<Setter Property="Control.Background" Value="#BB252525"/>
</Style>
That code works fine but I actually need to bind the background color to this resource:
<Color x:Key="MenuBackground">#BB252525</Color>
And when I do this:
<Style x:Key="someStyle" TargetType="{x:Type Border}">
<Setter Property="Control.Background" Value="{DynamicResource MenuBackground}"/>
</Style&开发者_StackOverflow中文版gt;
I get the following error:
How could I set the background property equal to the resource MenuBackground. What am I doing wrong?
You need to bind to a Brush
, not a Color
as Background
is a Brush
property.
<Application.Resources>
<SolidColorBrush x:Key="MenuBackground" Color="#BB252525"/>
</Application.Resources>
Application.Resources
could be Control.Resources
or other .Resources respectively.
精彩评论