gpt4 book ai didi

c# - wpf中的椭圆按钮

转载 作者:太空宇宙 更新时间:2023-11-03 11:28:40 31 4
gpt4 key购买 nike

我可以在不覆盖所有模板的情况下创建一个椭圆形按钮吗?

我有一个 TargetType=button 的模板和样式,我希望我的椭圆按钮获得这些模板。

提前致谢

最佳答案

好吧,这可行,尽管它不是最灵活的解决方案:

<Button>   
<Button.OpacityMask>
<VisualBrush>
<VisualBrush.Visual>
<Grid Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType=Button, AncestorLevel=1}}" Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType=Button, AncestorLevel=1}}">
<Ellipse Fill="White" />
</Grid>
</VisualBrush.Visual>
</VisualBrush>
</Button.OpacityMask>
</Button>

基本上,您只需告诉按钮控件只显示与 OpacityMask 中的椭圆重叠的部分,在本例中这是一个视觉画笔。对于一个快速而肮脏的解决方案,这将起作用,尽管我确实认为最好的选择是简单地从 here (msdn) 复制默认控件模板。并根据您的使用稍微调整一下。把它放在一个资源文件中,并像那样很好地分开。

关于c# - wpf中的椭圆按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8547706/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com