【发布时间】:2011-12-17 20:26:40
【问题描述】:
我可以在不覆盖所有模板的情况下创建一个椭圆按钮吗?
我有一个 TargetType=button 的模板和样式,我希望我的椭圆按钮获得这些模板。
提前致谢
【问题讨论】:
标签: c# wpf templates xaml styles
我可以在不覆盖所有模板的情况下创建一个椭圆按钮吗?
我有一个 TargetType=button 的模板和样式,我希望我的椭圆按钮获得这些模板。
提前致谢
【问题讨论】:
标签: c# wpf templates xaml styles
好吧,这行得通,虽然它不是最灵活的解决方案:
<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) 复制默认控制模板并稍微调整它以适应您的使用。把它放在一个资源文件中,然后像这样很好地分开。
【讨论】: