只是一個簡短的問題,澄清一些疑惑。元素綁定到依賴項屬性時,setter是否不運行?Setters不在依賴屬性上運行?
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}" />
正如我注意到下面我二傳手不運行
Debug.WriteLine("Setting value of TextContent: " + value);
如果在二傳手把斷點,可以看到它被設置。 – VoodooChild 2010-11-19 13:24:07
如果您在設置屬性時需要執行代碼,請查看UIMetadata類的CoerceValueCallback或ValueChangedCallback。 – Jens 2010-11-19 14:04:56
可能重複[WPF:XAML屬性聲明不是通過Setters?](http://stackoverflow.com/questions/3836076/wpf-xaml-property-declarations-not-being-set-via-setters) – 2015-09-14 13:30:57