如何订阅改变DependencyProperty?

发布于 2024-12-20 21:52:24 字数 388 浏览 4 评论 0原文

可能的重复:
监听依赖属性的更改

请原谅我的英语。

我需要创建一个可以订阅更改 DependencyProperty 的类,并根据该属性的新值来执行某些操作。

就像这样:

MyClass obj = new MyClass();
obj.Subscribe(TextBox.TextProperty, myTextBox);

我该怎么做?

Possible Duplicate:
Listen to changes of dependency property

Excuse me for my English.

I need to create a class that could subscribe to change DependencyProperty, and depending on the new value of this property to perform some action.

Like this:

MyClass obj = new MyClass();
obj.Subscribe(TextBox.TextProperty, myTextBox);

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏别ゝ 2024-12-27 21:52:24

这是一种方法,使用方便的 DependencyPropertyDescriptor 类。

 var pd = DependencyPropertyDescriptor.FromProperty(TextBox.TextProperty, typeof(TextBox));
 pd.AddValueChanged(myTextBox, OnTextChanged);


 private void OnTextChanged(object sender, EventArgs e)
 {
     ...
 }

Here is one way of doing it, using the handy DependencyPropertyDescriptor class.

 var pd = DependencyPropertyDescriptor.FromProperty(TextBox.TextProperty, typeof(TextBox));
 pd.AddValueChanged(myTextBox, OnTextChanged);


 private void OnTextChanged(object sender, EventArgs e)
 {
     ...
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文