【发布时间】:2015-05-27 10:25:28
【问题描述】:
我正在设计一个带有圆形扁平按钮的 WPF 用户界面。我为这种按钮编写了以下代码:
<Border BorderThickness="1"
BorderBrush="Transparent"
Background="DarkCyan"
CornerRadius="4"
Height="35"
Width="75">
<Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
Content="Enter"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Background="DarkCyan"
Foreground="White"/>
</Border>
这个按钮的样式正是我所需要的。但是在运行时,当鼠标移动到按钮上时,它就不再四舍五入了。它是一个大小相同的矩形。实际上,按钮溢出了边框。所以我在边框上添加了padding,如下所示:
<Border BorderThickness="1"
BorderBrush="Transparent"
Background="DarkCyan"
CornerRadius="4"
Height="35"
Width="75"
Padding="2">
<Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
Content="Enter"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Background="DarkCyan"
Foreground="White"/>
</Border>
在这种情况下,hoover mode 中的按钮不再溢出边框,但它仍然是矩形,因此按钮的颜色(在 hoover mode 中)在这个矩形和边框的其他空间中有所不同。所以不幸的是它还没有用。
现在我的问题是:有没有办法构建一个圆角扁平按钮(就像我提到的那样),移动到按钮上的标记空间恰好是圆角空间?
【问题讨论】:
-
WPF Button Styling Trigger 的可能重复项
-
不是严格意义上的 1:1 复制,但您需要的是覆盖按钮的悬停样式。
标签: wpf