1

カスタムの Bindable RichText Box を作成したので、Document プロパティにバインドできます。

ただし、ドキュメントのコンテンツを設定するとすぐに、受け入れる唯一のキーボード入力はバックスペース キー (???) です。他のキーボード入力は認識されません (矢印キーを含む)。

何か案は?

BindableRTB クラスのコードは次のとおりです。

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

クラス終了

4

1 に答える 1

1

あはは!解決しました。

私が言及しなかったこと(関連性がないように思われたため、このコントロールはWinFormsアプリケーションから起動されたWPFウィンドウにあるということでした)

WPFウィンドウを起動するときに、ElementHost.EnableModelessKeyboardInterop()を呼び出して、次のように新しいウィンドウへの参照を渡す必要がありました。

 Dim wpfEdit As New WpfEditor
 System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(wpfEdit)
    myParent.ShowNewWPFWindow(wpfEdit)
于 2010-02-03T17:00:09.657 に答える