Reputation: 47
I need to call static resource for button style in code-behind using C#
This is my Button in XAML:
<Button Height="48" HorizontalAlignment="Left" Margin="229,0,0,0" Name="btnlogin"
VerticalAlignment="Top" Width="90" Grid.Row="6" BorderThickness="0"
MouseEnter="btnlogin_MouseEnter" MouseLeave="btnlogin_MouseLeave"
BorderBrush="Transparent"
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
<Button.Background>
<ImageBrush ImageSource="/BaccaratDealerInterfaceWPF;component/Images/Login_Button_Normal.png" />
</Button.Background>
</Button>
I need to set this Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
to btnlogin.Style
property in code behind C#.
I've tried
Style style = this.FindResource("{x:Static ToolBar.ButtonStyleKey}") as Style;
btnlogin.Style = style;
Upvotes: 1
Views: 3110
Reputation: 3683
Try
this.FindResource(ToolBar.ButtonStyleKey);
Here's the Microsoft Documentation for this style and how to access it in both:
ToolBar.ButtonStyleKey
<object property="{x:Static ToolBar.ButtonStyleKey}"/>
Upvotes: 4