自定义控件与 MVVM 设计模式详解
1. 自定义控件开发
1.1 创建 GroupBox 控件
首先,我们来创建一个自定义的 GroupBox 控件。以下是其基本代码:
public GroupBox()
{
DefaultStyleKey = typeof(GroupBox);
}
public static readonly DependencyProperty HeaderTextProperty =
DependencyProperty.Register("HeaderText", typeof(string),
typeof(GroupBox), null);
public string HeaderText
{
get { return (string)GetValue(HeaderTextProperty); }
set { SetValue(HeaderTextProperty, value); }
}
通过上述代码,我们定义了 GroupBox 控件,并为其添加了一个 HeaderText 属性。现在,我们可以使用内容元素语法为该控件分配内容,示例如下:
<my:GroupBox Height="120" Width="250" HeaderText="GroupB
超级会员免费看
订阅专栏 解锁全文
7万+

被折叠的 条评论
为什么被折叠?



