我正在使用 WPF 用户控件并有以下问题:为什么在将属性设置为 a 之后属性初始化/赋值的行为会发生变化DependencyProperty
?
让我简要说明一下:
考虑这个UserControl
类的代码:
public partial class myUserControl : UserControl
{
private string _blabla;
public myUserControl()
{
InitializeComponent();
_blabla = "init";
}
//public static DependencyProperty BlaBlaProperty = DependencyProperty.Register(
// "BlaBla", typeof(string), typeof(UserControlToolTip));
public string BlaBla
{
get { return _blabla; }
set { _blabla = value; }
}
}
这就是UserControl
在 XAML 文件中初始化的方式:
<loc:myUserControl BlaBla="ddd" x:Name="myUsrCtrlName" />
我遇到的问题是行set { _blabla = value; }仅在注释掉DependencyProperty声明时调用(根据此示例)。但是,当DependencyProperty行成为程序的一部分时,set { _blabla = value; }行不再被系统调用。
有人可以向我解释这种奇怪的行为吗?
太感谢了!