Ana*_*aev 15
作为替代方案,您可以尝试这样做:
XAML
<Button Name="FlatButton" Width="100" Height="30" Content="Test" />
Run Code Online (Sandbox Code Playgroud)
Code behind
private void Button_Click(object sender, RoutedEventArgs e)
{
FlatButton.Style = (Style)FindResource(ToolBar.ButtonStyleKey);
}
Run Code Online (Sandbox Code Playgroud)
这是一种有效的解决方法.添加基于一种风格ToolBar.ButtonStyleKey,以Window.Resources如下:
<Window.Resources>
<Style x:Key="MyStyle" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" TargetType="Button" />
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
然后,在代码中,根据此问题中的第一个链接引用它:
button.Style = this.Resources["MyStyle"] as Style;
Run Code Online (Sandbox Code Playgroud)
我更喜欢有一个仅代码解决方案(没有XAML),但这也适用.