Jie*_*eng 4 wpf dependency-properties
我发现当我改变班级时
public class MarkdownEditorOptions : ObservableObject
Run Code Online (Sandbox Code Playgroud)
到
public class MarkdownEditorOptions : INotifyPropertyChanged, DependencyObject
Run Code Online (Sandbox Code Playgroud)
因为我想使用依赖属性,所以出现错误
“Options”属性的默认值无法绑定到特定线程。...\Views\ShellView.xaml
选项被声明为依赖属性ShellViewModel
public MarkdownEditorOptions Options
{
get { return (MarkdownEditorOptions)GetValue(OptionsProperty); }
set { SetValue(OptionsProperty, value); }
}
public static readonly DependencyProperty OptionsProperty =
DependencyProperty.Register("Options", typeof(MarkdownEditorOptions), typeof(ShellViewModel), new UIPropertyMetadata(new MarkdownEditorOptions()));
Run Code Online (Sandbox Code Playgroud)
怎么了?
看看这些问题
您的 Dependency 属性不是线程安全的,这意味着它不是从 System.Windows.Freezable 继承的。
将 DependencyObject 更改为 Freezable,它将起作用,因为 Freezable 派生自 DependencyObject。