我希望我的WPF工具栏中的按钮看起来像标准按钮。也就是说,我希望它们使用默认的按钮样式,但工具栏会将自己的“ToolBar.ButtonStyleKey”样式应用于这些按钮。我尝试过以下方法...
<ToolBar>
<Button Content="A Button" Style="{StaticResource {x:Type Button}}" />
</ToolBar>
... 但是工具栏中的按钮看起来仍然像一个文本块(没有边框、背景等)。
我希望我的WPF工具栏中的按钮看起来像标准按钮。也就是说,我希望它们使用默认的按钮样式,但工具栏会将自己的“ToolBar.ButtonStyleKey”样式应用于这些按钮。我尝试过以下方法...
<ToolBar>
<Button Content="A Button" Style="{StaticResource {x:Type Button}}" />
</ToolBar>
... 但是工具栏中的按钮看起来仍然像一个文本块(没有边框、背景等)。
在我使用 Windows 10 上,您的示例可以正常工作。
您还可以尝试以下方法:
<ToolBar>
<ToolBar.Resources>
<Style x:Key="{x:Static ToolBar.ButtonStyleKey}" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}" />
</ToolBar.Resources>
<Button Content="A Button" />
</ToolBar>
只需使用,不需要任何样式。
<ToolBar>
<Button Content="A Button" />
</ToolBar>
编辑 误读问题,这应该没有任何问题
<ToolBar>
<Button Content="A Button" Style="{StaticResource {x:Type Button}}" />
</ToolBar>