“选项”属性的默认值不能绑定到特定线程 [英] Default value for the 'Options' property cannot be bound to a specific thread
本文介绍了“选项”属性的默认值不能绑定到特定线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现当我从
public class MarkdownEditorOptions : ObservableObject
至
public class MarkdownEditorOptions : INotifyPropertyChanged, DependencyObject
当我想使用依赖项属性时,出现错误
as I wanted to use dependency properties, I get the error
'Options'属性的默认值不能绑定到特定线程。 ... \Views\ShellView.xaml
Default value for the 'Options' property cannot be bound to a specific thread. ...\Views\ShellView.xaml
选项在 ShellViewModel <中声明为依赖项属性/ code>
Options is declared as a dependency property on 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()));
出什么问题了?
推荐答案
查看以下问题
- Why Would a Dependency-Property Implementation Crash My Application When I Provide a Default Value?
- Attached Property: 'System.TypeInitializationException' when setting default value
您的Dependency属性不是线程安全的,这意味着它不继承自System.Windows.Freezable
将DependencyObject更改为Freezable,因为Freezable源自DependencyObject,所以它将起作用。
Your Dependency property is not thread safe, meaning that it doesn't inherit from System.Windows.Freezable.
Change DependencyObject to Freezable and it'll work since Freezable derives from DependencyObject.
这篇关于“选项”属性的默认值不能绑定到特定线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文