I wonder if theres something wrong with my dependency property?
// In MarkdownEditor.xaml.cs, DataContext for MarkdownEditor.xaml
public string TextContent
{
get { return (string)GetValue(TextContentProperty); }
set { SetValue(TextContentProperty, value); }
}
public static readonly DependencyProperty TextContentProperty =
DependencyProperty.Register("TextContent", typeof(string), typeof(MarkdownEditor), new UIPropertyMetadata(""));
When TextContent
is set in XAML like
<me:MarkdownEditor TextContent="{Binding TextContent}" Options="{Binding Options}" />
It fails ... when I do
<me:MarkdownEditor TextContent="Hello world" Options="{Binding Options}" />
It works ... Is there something wrong? A similar thing seems to be happening to options
UPDATE 1
I notice that the binding with a normal text box works fine
<TextBox Text="{Binding TextContent}" />
FYI: In MarkdownEditor.xaml
<TextBox Text="{Binding TextContent}"
FontFamily="{Binding Path=Options.FontFamily}"
FontSize="{Binding Path=Options.FontSize}"
FontWeight="{Binding Path=Options.FontWeight}"
Background="{Binding Path=Options.Background}"
Foreground="{Binding Path=Options.Foreground}" />
UPDATE 2
Oh! I wonder if when I do
<me:MarkdownEditor TextContent="{Binding TextContent}" Options="{Binding Options}" />
Where does the properties TextContent
& Options
come from? MarkdownEditor
's ViewModel?
UPDATE 3
Another few observations:
Barebones
<me:MarkdownEditor />
TextContent
will be set to the value from MarkdownEditor
's constructor
public MarkdownEditor()
{
InitializeComponent();
DataContext = this;
TextContent = "From MarkdownEditor.xaml.cs";
}
Static Value
<me:MarkdownEditor TextContent="Static Value" />
The string "Static Value" is shown
Binding
<me:MarkdownEditor TextContent="{Binding Path=TextContent}" />
value from Dependency Property declaration is shown
public static readonly DependencyProperty TextContentProperty =
DependencyProperty.Register(..., new UIPropertyMetadata("Default"));