In my application I have several menus with the same background color, corner radius,border color and border thickness. I save those properties as resources in my application resources so that if I change the background color for example it will change the color of all my menus. I was wondering if it is possible to create a style so that I can just bind that style to the menus instead of binding so many properties. Moreover I just want to apply that style to some borders because not all borders in my application are menus. How could I do that?
for example I am hoping to do something like:
here is my style in my application resources:
<Style x:Key="someStyle">
<Style.Resources>
<Color x:Key="MenuBackground2">#BB252525</Color>
<CornerRadius x:Key="CornerRadiusMenu2">7</CornerRadius>
<Border x:Key="MainBorder2" >
<Border.Background>
<SolidColorBrush Color="{DynamicResource MenuBackground}"/>
</Border.Background>
</Border>
</Style.Resources>
</Style>
and then on MainWindow.xaml place:
<Border Margin="498,90,25,0" Name="brdMain" Style="{DynamicResource someStyle}"></Border>
but when I do that, brdMain does not seem to bind to that style…
Your
Styleis not correctly defined. It should be a collection ofSetters. For example, your given style should be:A
Styleis little more than a bunch of property setters. You can only set properties of the object to which theStylehas been applied.