简短的问题,以澄清一些疑惑。当元素绑定到依赖属性时,setter没有被运行吗?
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}" />
我发现我的 setter 方法下面的代码没有运行
Debug.WriteLine("Setting value of TextContent: " + value);
IValueConverter
来修复它,但是在设置参数时遇到了麻烦(参数也可以更改)。在我的情况下,一个依赖属性会改变另外两个属性,UI也会相应地更新。ValueChangedCallback
就是解决方案。我正在DependencyProperty.Register
函数中寻找它,没有意识到它是元数据的一部分,但现在我可以看到为什么了。再次感谢。 - nurchi