如何在WPF工具栏中使用标准按钮样式?

3

我希望我的WPF工具栏中的按钮看起来像标准按钮。也就是说,我希望它们使用默认的按钮样式,但工具栏会将自己的“ToolBar.ButtonStyleKey”样式应用于这些按钮。我尝试过以下方法...

<ToolBar>
    <Button Content="A Button" Style="{StaticResource {x:Type Button}}" />
</ToolBar>

... 但是工具栏中的按钮看起来仍然像一个文本块(没有边框、背景等)。


2
你的例子对我来说可行。我有一个带有标准按钮的工具栏。 - I.B
2个回答

4

在我使用 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>

1

只需使用,不需要任何样式。

<ToolBar>
       <Button Content="A Button" />
</ToolBar>

编辑 误读问题,这应该没有任何问题

<ToolBar>
    <Button Content="A Button" Style="{StaticResource {x:Type Button}}" />
</ToolBar>

这实际上会移除标准样式并使其看起来像是一个文本块,而这正是他所不想要的相反效果。 - I.B

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接