2010-05-24 103 views
19

我想摆脱按钮边框,只显示文本,但是即使我将borderThickness设置为0并将borderbrush设置为透明,文本周围的细线也会显示出来。为保存按钮 alt text http://i45.tinypic.com/scywye.png摆脱WPF中的按钮边框?

我的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"/> 

反正我有可以摆脱按键边框?

+0

短劈:'<按钮了borderThickness = “0” 形式= “{StaticResource的{X:静态ToolBar.ButtonStyleKey}}”>',从[相似柱](http://stackoverflow.com/questions/995757/how-do-you-completely-remove-the-button-border-in-wpf) – 2014-12-10 09:24:49

回答

47

你需要重写按钮的控件模板:

<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> 
+3

您的建议将删除按钮的所有高亮/按下样式。 – 2010-12-28 03:31:14

+2

是的。如果你想保留这个,你必须得到一个控制模板的副本(例如使用表达式混合)来修改它(并且保留在你想要保留的部分),然后将它应用到你的按钮上。 – bitbonk 2011-01-03 08:40:04

2

您需要为您的按钮,一个新的模板。

最简单的方法是在Expression Blend中打开项目,选择按钮,然后右键单击并选择“编辑模板>编辑副本”。这会将现有模板复制到您可以修改的模板中。如果您在资源字典中创建它会更容易。

然后选择模板,然后在资源选项卡(UI的右侧)上选择ButtonFocusVisual。选择“属性”选项卡并展开“其他”部分。这有BorderStyle和BorderThickness字段(等等)。将样式设置为无。

+0

我按照您的指南,但未能删除边框。我在这里发布问题http://stackoverflow.com/questions/4553692/how-to-remove-buttonchrome-border-when-defining-the-template-of-a-border。 请支持我们。 – 2010-12-29 14:04:13

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" /> 
+1

圣斗丹!这是天才! – 2013-09-09 19:08:29

+1

需要注意的一点是,如果按钮位于工具栏内,它将不起作用。 – 2017-01-11 15:28:34