Default value for the 'Options' property cannot be bound to a specific thread
I find that when I change a class from
public class MarkdownEditorOptions : ObservableObject
to
public class MarkdownEditorOptions : INotifyPropertyChanged, DependencyObject
as I wanted to use dependency properties, I get the error
Default value for the 'Options' property cannot be bound to a specific thread. ...\Views\ShellView.xaml
Optio开发者_如何学Gons 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()));
whats wrong?
See these questions
- Why Would a Dependency-Property Implementation Crash My Application When I Provide a Default Value?
- Attached Property: 'System.TypeInitializationException' when setting default value
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.
精彩评论