1
我想通过使用我的CornerRadius属性创建带有圆角的ToggleButton。正如你在下面的代码中看到的,我已经为我的xaml ToggleButton添加了一个cornerRadius属性来传递一个半径值。但我找不到在c#中使用此值的方法来创建具有圆角的ToggleButton。C#/ WPF - 向ToggleButton添加CornerRadius
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" />
所以,我怎么可以用我的财产 “CornerRadius” 创建一个切换按钮圆角? 如果有人能帮助我,那会很棒。
感谢您的快速反应,但我相当新的WPF。我应该将我的CornerRadius属性绑定到ToggleButton默认控件模板副本的边框上。这可能是一个愚蠢的问题,但我找不到一种方法将c#class myToggleButton链接到模板。 – Richard
[本文](http://msdn.microsoft.com/en-us/library/ms745025.aspx)是一个很好的开始,以了解如何在WPF中扩展/自定义控件。 –
感谢您的帮助,文章非常棒。 – Richard