设置程序不能在依赖属性上运行吗? [英] Setters not run on Dependency Properties?

查看:77
本文介绍了设置程序不能在依赖属性上运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简短的问题,以澄清一些疑问。将元素绑定到依赖项属性时,setter不会运行吗?

Just a short question, to clarify some doubts. Are setters not run when an element is bound to a dependency property?

public string TextContent
{
    get { return (string)GetValue(TextContentProperty); }
    set { SetValue(TextContentProperty, value); Debug.WriteLine("Setting value of TextContent: " + value); }
}

public static readonly DependencyProperty TextContentProperty =
    DependencyProperty.Register("TextContent", typeof(string), typeof(MarkdownEditor), new UIPropertyMetadata(""));

...

<TextBox Text="{Binding TextContent}" />

正如我在我的二传手中注意到的那样,以下内容没有运行

As I noticed the below in my setter does not run

Debug.WriteLine("Setting value of TextContent: " + value);


推荐答案

WPF绑定引擎调用直接获取GetValue SetValue (绕过属性设置器和获取器)。您需要该属性,以便可以在XAML标记中支持该属性(并正确编译)。

The WPF binding engine calls GetValue and SetValue directly (bypassing the property setters and getters). You need the property to be there so it can be supported in the XAML markup (and compile correctly).

这篇关于设置程序不能在依赖属性上运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆