views:

174

answers:

1

I have written a custom Bindable RichText Box, so I can bind to the Document property.

However, as soon as I set my document content, the only keyboard input it accepts is the backspace key (???). No other keyboard input is acknowledged (including the arrow keys).

Any ideas?

Here is the code of my BindableRTB class:

Imports System.Windows.Documents
Imports System.Windows
Imports System.Windows.Controls

Public Class BindableRTB
    Inherits System.Windows.Controls.RichTextBox




Public Shared DocumentProperty As DependencyProperty = DependencyProperty.Register("Document", GetType(FlowDocument), _
                          GetType(BindableRTB), New FrameworkPropertyMetadata(Nothing, _
                            New PropertyChangedCallback(AddressOf OnDocumentChanged)))
Sub New()
    MyBase.new()
    Me.IsReadOnly = False
    Me.IsDocumentEnabled = True

End Sub

Public Overloads Property Document() As FlowDocument
    Get
        Return CType(MyBase.GetValue(DocumentProperty), FlowDocument)
    End Get
    Set(ByVal value As FlowDocument)
        MyBase.SetValue(DocumentProperty, value)
    End Set
End Property

Private Shared Sub OnDocumentChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)        Console.WriteLine("doc changed")
    Dim rtb As RichTextBox = CType(d, RichTextBox)
    rtb.Document = CType(e.NewValue, FlowDocument)
End Sub

End Class

A: 

AH-ha! Solved it.

What I hadn't mentioned (because it didn't seem relevant, was that this control is in a WPF window, launched from a WinForms application)

When launching my WPF window, I needed to call ElementHost.EnableModelessKeyboardInterop() and pass in a reference to my new window, like this:

 Dim wpfEdit As New WpfEditor
 System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(wpfEdit)
    myParent.ShowNewWPFWindow(wpfEdit)
Matt H.