如何用图形路径完全替换WPF按钮的内容?
我已经使用 Blend 解构了一个标准 WPF 按钮,并设法创建了一个样式精美的按钮,但我无法弄清楚如何使路径填充按钮空间的内部(按钮宽度和高度)。 我也不确定是否需要指定 ContentPresenter 或者它是否正确。 我在按钮中间的文本后面(正常情况下),但后面有我的图形路径。
谁能给我关于如何实现这一目标的反馈? 样式定义为;
<ControlTemplate x:Key="CurvedButton" TargetType="{x:Type Button}">
<Grid>
<Path Fill="#ff951c1f" Data="F1 M 64,16 C 64,24 56,31 48,31 L 15,31 C 7,31 0,24 0,16 C 0,7 7,0 15,0 L 48,0 C 56,0 64,7 64,16 Z" />
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" />
</Grid>
</ControlTemplate>
该按钮的用途是;
<StackPanel>
<Button Template="{StaticResource CurvedButton}" FontFamily="MS Trebuchet" FontSize="40" Width="200" Height="120" Foreground="Black">XXXXXXXXXXX</Button>
</StackPanel>
一切完成后,它应该看起来像一个弯曲的红色按钮。
预先感谢
瑞安
I've deconstructed a standard WPF button using Blend and have managed to create a nicely styled button, but I cannot figure out how to make the path fill the interior of the button space (the button width and height). I am also not sure if I need to specify ContentPresenter or even if it is correct. I am after the text in the middle of the button (as normal) but with my graphic path behind it.
Can anyone give me feedback on how to accomplish this? The style is defined as;
<ControlTemplate x:Key="CurvedButton" TargetType="{x:Type Button}">
<Grid>
<Path Fill="#ff951c1f" Data="F1 M 64,16 C 64,24 56,31 48,31 L 15,31 C 7,31 0,24 0,16 C 0,7 7,0 15,0 L 48,0 C 56,0 64,7 64,16 Z" />
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" />
</Grid>
</ControlTemplate>
The usage of this button is;
<StackPanel>
<Button Template="{StaticResource CurvedButton}" FontFamily="MS Trebuchet" FontSize="40" Width="200" Height="120" Foreground="Black">XXXXXXXXXXX</Button>
</StackPanel>
When all is done, it should just look like a curvy red button.
Thanks in advance
Ryan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以采取一些措施来获得您想要的结果。
将路径放入视图框中并使其拉伸以填充:
使用边框而不是路径:
There are a couple things you can do to get the results you're looking for.
Place the path in a viewbox and have it stretch to fill:
Use a border instead of a path: