I have a custom control with bindings like below
After reading Kent Boogaart's answer to this question I think that the right place to change SetValue to SetCurrentValue isn't in the CLR Property but in the constructor for MarkDownEditor.
public MarkdownEditor()
{
InitializeComponent();
//Options = new MarkdownEditorOptions();
this.SetCurrentValue(OptionsProperty, new MarkdownEditorOptions());
DataContext = this;
}
In fact, this will work just as good without this.SetCurrentValue also since Options will be set through the Binding.
To verify that your Binding has in fact been overwritten by SetValue you can add this code in some event for TabUsage (e.g PreviewMouseRightButtonDown for the FontSize TextBox) and the Binding will start to work again.
private void TextBox_PreviewMouseRightButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
MarkdownEditor.MarkdownEditor editor = VisualTreeHelpers.GetVisualChild(this);
Binding binding = new Binding();
binding.Path = new PropertyPath("Options");
binding.Source = this;
binding.Mode = BindingMode.TwoWay;
editor.SetBinding(MarkdownEditor.MarkdownEditor.OptionsProperty, binding);
}