以选项卡为中心的按钮边框颜色和样式
我的用户控件中有此按钮:
<Button
x:Name="OkButton"
Grid.Column="1"
Command="{Binding Confirm}"
IsDefault="True"
IsEnabled="{Binding ConfirmEnabled}"
Style="{StaticResource okCancelbuttons}"
Visibility="{Binding ConfirmVisibility}">
<Image
Grid.Column="0"
Margin="0"
Source="{DynamicResource ResourceKey=confirm_res}" />
<!-- Style Dictionary -->
<Style x:Key="okCancelbuttons" TargetType="{x:Type Button}">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="3" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border
x:Name="Border"
Padding="3"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="0"
CornerRadius="3"
Style="{DynamicResource bordoPulsante}">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Resources>
<Style TargetType="Image">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Opacity" Value="1" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</Style.Triggers>
</Style>
</Style.Resources>
</Style>
<Style x:Key="bordoPulsante" TargetType="{x:Type Border}">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="CornerRadius" Value="3" />
<Setter Property="Background" Value="Transparent" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource brushverdechiaro}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Background" Value="Transparent" />
</Trigger>
</Style.Triggers>
</Style>
可能会有人想重复浏览 tab 的表格,但虽然其他控件明显突出显示,但这些按钮显示了这个非常微小的黑线。几乎看不到:
“似乎对此有效。 有建议吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个专用属性,称为 focusVisualStyle 在
frameworkelement
。虽然您可以创建设置器并提供控制模板,这不是很灵活,因为它在控制模板的顶部添加了控制模板。
这是您自己风格的焦点视觉风格的示例。聚焦时,包含的模板在按钮周围绘制了两个像素宽的蓝线。
一种更灵活的方法是使用
isfocused
和iSkeyboardFocusWithin
样式或控制模板的设置中的属性。后者允许您通过用targetName
引用控制模板中任何控件的属性。另请注意,
focusVisualStyle
明确设置为{x:null}
,以便使用虚线边框删除默认的焦点样式。来自文档关于改变焦点视觉样式的文档:
有关更多信息,您可以参考以下文章:
There is a dedicated property called
FocusVisualStyle
onFrameworkElement
.Although you can create setters and supply a control template, this is not very flexible, as it adds the control template on top of the control template of the control itself.
Here is an example of a focus visual style in your own style. The contained template draws a two pixels wide blue line around the button when focused.
A more flexible approach is to use the
IsFocused
andIsKeyboardFocusWithin
properties in setters of the style or the control template. The latter allows you to change properties of any control within the control template by referencing it withTargetName
.Please also note, that the
FocusVisualStyle
is explicitly set to{x:Null}
in order to remove the default focus style with the dashed border.A word of caution from from the documentation on changing focus visual styles:
For more information, you can refer to the following articles: