私は WPF ユーザーコントロールをいじっていて、次の質問があります: プロパティが に作成された後にプロパティの初期化/割り当ての動作が変わるのはなぜ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; }行はシステムによって呼び出されなくなりました。
この奇妙な振る舞いを私に説明してもらえますか?
どうもありがとう!