我需要使用C#
在代码隐藏中为按钮样式调用静态资源这是我在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>
我需要在C#后面的代码中将此Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
设置为btnlogin.Style
属性。
我试过
Style style = this.FindResource("{x:Static ToolBar.ButtonStyleKey}") as Style;
btnlogin.Style = style;
答案 0 :(得分:3)
尝试
this.FindResource(ToolBar.ButtonStyleKey);
以下是此款式的Microsoft Documentation以及如何在以下两种方式中访问它:
ToolBar.ButtonStyleKey
<object property="{x:Static ToolBar.ButtonStyleKey}"/>