wpf WPF按钮无边框无背景

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7769979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 23:07:56  来源:igfitidea点击:

WPF Button No Border No Background

wpfbuttonstyles

提问by paparazzo

I just need a button so simple that it looks like a TextBlock. Some time ago I saw an answer on SO to style the button based on a static style for a button in a menu but I cannot find that answer (and I have been searching for an hour). Does anyone know what system style I am referring to and the syntax to apply that style to a button?

我只需要一个看起来像 TextBlock 的简单按钮。前段时间我在 SO 上看到了一个答案,根据菜单中按钮的静态样式来设置按钮样式,但我找不到那个答案(我已经搜索了一个小时)。有谁知道我指的是什么系统样式以及将该样式应用于按钮的语法?

回答by IanR

Is it maybe the style used for a button in a ToolBar that you're referring to? The ToolBar control overrides the Button style so they appear flat. You can apply that style to a button like this...

它可能是您所指的工具栏中按钮的样式吗?ToolBar 控件会覆盖 Button 样式,因此它们看起来是扁平的。您可以将该样式应用于这样的按钮...

<Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" />

回答by Jay

If you want a button that looks like a TextBlock, you can make a button that isa TextBlock.

如果你想有一个按钮,看起来像TextBlock,可以使一个按钮,一个TextBlock

<Button Content="I'm a Button; click me">
    <Button.Template>
        <ControlTemplate TargetType="Button">
            <TextBlock Text="{TemplateBinding Content}" />
        </ControlTemplate>
    </Button.Template>
</Button>