I was getting some nice crashes on startup while trying to do some data binding to the Document property on RichTextBox under WPF and so I hit the net and found out that it's not possible. I quickly came up with the following code, which seems to work:
class BindableRichTextBox : RichTextBox
{
public static readonly DependencyProperty DocumentProperty = DependencyProperty.Register("Document", typeof(FlowDocument), typeof(BindableRichTextBox), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnDocumentChanged)));
public new FlowDocument Document
{
get { return (FlowDocument)GetValue(DocumentProperty); }
set { SetValue(DocumentProperty, value); }
}
static void OnDocumentChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
RichTextBox rtb = (RichTextBox)obj;
rtb.Document = (FlowDocument)args.NewValue;
}
}
Now the problem I have is that I don't know why the framework doesn't do this itself and if it's going to cause me massive problems further down the road.