摆脱WPF中的按钮边框?

san*_*084 20 wpf border button

我试图摆脱按钮边框,只显示文本,但是即使我将borderThickness设置为0并将borderbrush设置为透明,也会显示文本周围的细线. 替代文字http://i45.tinypic.com/scywye.png

我的保存按钮的xaml代码:

<Button Content="save" Name="btnSaveEditedText" 
                Background="Transparent" 
                Foreground="White" 
                FontFamily="Tw Cen MT Condensed" 
                FontSize="30" 
                Margin="-280,0,0,10"
                Width="60"
                BorderBrush="Transparent"
                BorderThickness="0"/>
Run Code Online (Sandbox Code Playgroud)

无论如何我可以摆脱按钮边框?

bit*_*onk 47

您需要覆盖Button的ControlTemplate:

<Button Content="save" Name="btnSaveEditedText" 
                Background="Transparent" 
                Foreground="White" 
                FontFamily="Tw Cen MT Condensed" 
                FontSize="30" 
                Margin="-280,0,0,10"
                Width="60"
                BorderBrush="Transparent"
                BorderThickness="0">
    <Button.Template>
        <ControlTemplate TargetType="Button">
             <ContentPresenter Content="{TemplateBinding Content}"/>
        </ControlTemplate>
    </Button.Template>
</Button>
Run Code Online (Sandbox Code Playgroud)

  • 您的建议将删除按钮的所有突出显示/按下的样式. (3认同)
  • 是.如果你想保留它,你必须得到一个控制模板的副本(例如使用表达式混合)修改它(并留在你想要保留的部分)然后将它应用到你的按钮. (2认同)

小智 11

我最近发现对此最有用的方法是让按钮使用工具栏的样式.这只会在鼠标悬停时显示按钮边框时使用图像或文本.

<Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
        Content="save"
        Name="btnSaveEditedText" 
        Background="Transparent" 
        Foreground="White" 
        FontFamily="Tw Cen MT Condensed" 
        FontSize="30" 
        Margin="-280,0,0,10"
        Width="60"
        BorderBrush="Transparent"
        BorderThickness="0" />
Run Code Online (Sandbox Code Playgroud)