[英]How to get rid of this border around image embed button?
I am trying to get rid of this white border around my buttons. 我试图摆脱按钮周围的白色边框。 I am adding an Image to a Button
. 我将图像添加到Button
。 It does not seem to be the button itself, but the border of the image. 它似乎不是按钮本身,而是图像的边框。
This is the XAML, 这是XAML,
<Style x:Key="MyButton" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border" BorderThickness="0" Background="{TemplateBinding Background}" CornerRadius="5" >
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And the Button
itsself, 而Button
本身,
<Button Name="Button2" Content="stuff" Height="25" Grid.Column="1" Grid.Row="1"
Style="{StaticResource MyButton}" Click="Button2_OnClick">
<Button.Background>
<ImageBrush ImageSource="Images\ButtonEnterLight.png"></ImageBrush>
</Button.Background>
</Button>
And this is the result, 结果就是这样
What else do I need to do to get this to disappear? 我还需要做些什么才能使它消失? It has been bothering me for the last week. 上周一直困扰着我。
EDIT: This is a Screen shot of the Live Visual Tree expanded to the first button that has an Image embedded in it. 编辑:这是实时视觉树的屏幕快照,扩展为嵌入图像的第一个按钮。
Alright, so FocusVisualStyle is an often overlooked System.Windows.Style property value that in many instances adds a resource to help visualization of when a control has active focus. 好吧,因此FocusVisualStyle是一个经常被忽略的System.Windows.Style属性值,在许多情况下,该属性值添加了有助于可视化控件何时具有活动焦点的资源。
It may not always be evident in the Style
template you're working in since the default is an empty static style but also often value effective at runtime. 由于您使用的Style
模板的默认值是一个空的静态样式,但在运行时通常值有效,因此它可能并不总是显而易见的。 So what often ends up happening is even if you've declared your Triggers or Visual States for the elements in the template. 因此,即使您已经为模板中的元素声明了“触发器”或“可视状态”,也经常会发生这种情况。 A ghostly border or something else visual will occur on an element that you didn't explicitly set. 未明确设置的元素上会出现鬼影边框或其他视觉效果。
To get around this, there's several things you can do. 为了解决这个问题,您可以做几件事。
Could overwrite it at the instance of the template with a setter, eg <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
可以使用设置器在模板实例上覆盖它,例如<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
[The value could also effectively be Transparent
, either way you just want to declare you don't want the BorderThickness to have color.] [该值也可以有效地是Transparent
,无论哪种方式,您只想声明自己不希望BorderThickness具有颜色。]
BorderThickness="0"
您也可以通过BorderThickness="0"
将边框全部BorderThickness="0"
从而在实例处BorderThickness="0"
The overall goal though, is to just deal with that property of FocusVisualStyle
and either wipe out its result, or hide it, so it's no longer a visual and you can move on with your day. 但是,总体目标是只处理FocusVisualStyle
该属性,然后擦除其结果或将其隐藏,因此它不再是一种视觉效果,您可以继续前进。
Hope this helps, cheers. 希望这会有所帮助,欢呼。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.