Reputation: 13
I want create a ToggleButton with round corners by using my CornerRadius property. As you can see in the code below, i already added a cornerRadius property to my xaml ToggleButton to pass a radius value. But i can't find a way to use this value in c# to create a ToggleButton with round corners.
C#
public static readonly DependencyProperty CornerRadiusProperty =
DependencyProperty.Register("CornerRadius", typeof(int), typeof(MyToggleButton),
new PropertyMetadata(0)); //Default CornerRadius = 0
public int CornerRadius
{
get { return (int)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
}
XAML
<custom:MyToggleButton Height="25" Content="Test" CornerRadius="15" />
So how can i create a toggleButton with round corners by using my property "CornerRadius"? Would be great if someone could help me.
Upvotes: 1
Views: 4844
Reputation: 25201
I wouldn't create a new control just in order to make it round - that's what templates are for and that's what makes WPF so great! You could simply define a new template for the ToggleButton
.
If you insist on inheriting your own control, you'll need to define for it a new default style that will also include a control template that will have a border that uses your CornerRadius
property. You can base your new template on the default control template for ToggleButton
.
Upvotes: 1