Reputation: 331
Can i create an ellipse button without override all the template?
I have a template and style for TargetType=button and i want my ellipse button get these template.
Thanks in advance
Upvotes: 2
Views: 5967
Reputation: 23820
Well, this works, although it's not the most flexible solution:
<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>
Basically you just tell the button control to only show the parts which overlap with the ellipse in the OpacityMask, which is a visual brush in this case. For a quick and dirty solution this will work, although I do think that the best option would be to simply copy the default control template from here (msdn) and adapt it slightly to your use. Put it in a resource file and keep it nicely separated like that.
Upvotes: 3