开发者

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:

Cannot bind to resource in my style wpf

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜