WPF Richtextbox Bindable in .net 4.5

Sma*_*tis 9 wpf richtextbox mvvm valueconverter .net-4.5

所以我试图在我的.net 4.5项目中使用David Veeneman的Bindable WPF RichTextBox.添加控件后,ValueConverter在我的代码中,我注意到只会public object Convert()触发但public object ConvertBack()不会触发.

在阅读了对该项目的评论后,我更改了控制源代码的以下部分.

private static void OnDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var thisControl = (EcoRichTextBox)d;
    if (thisControl.m_InternalUpdatePending > 0)
    {
        thisControl.m_InternalUpdatePending--;
        return;
    }
    // Changed:
    try
    {
        thisControl.TextBox.Document = (e.NewValue == null) ? new FlowDocument() : (FlowDocument)e.NewValue;
    }
    catch { }
    thisControl.m_TextHasChanged = false;
} 
Run Code Online (Sandbox Code Playgroud)

而这个事件处理程序:

private void OnTextChanged(object sender, TextChangedEventArgs e)
{
    // Set the TextChanged flag
    m_TextHasChanged = true;

    // Changed:
    Document = TextBox.Document;
}
Run Code Online (Sandbox Code Playgroud)

现在这两种方法的ValueConverter工作正常,但事件就像private void OnNormalTextClick(object sender, RoutedEventArgs e)导致FatalExecutionEngineError运行时一样.

所以我想知道WPF 3.5到4.5是否有重大变化?

或者任何人有想法解决这个问题?


更新

在XAML中绑定

<uc:FsRichTextBox Margin="5"
    Document="{Binding Path=Ereignis.Bericht, 
    Converter={StaticResource flowDocumentConverter}, 
    UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" />
Run Code Online (Sandbox Code Playgroud)

小智 0

我在 VS2015 中使用目标框架 4.0 和 4.5运行了您在此处链接的演示。当我取出双向数据绑定时,它不会更新。

添加到您的 RTB。两种方式的数据绑定和名称:

Mode=TwoWay 
x:Name="EditBox" 
Run Code Online (Sandbox Code Playgroud)

我认为与其自己管理文本更改,不如删除它:

// Changed:
Document = TextBox.Document;
Run Code Online (Sandbox Code Playgroud)

使用事件处理程序来更新数据。

然后在管理更新的事件处理程序中(我假设单击按钮?并允许它管理更新。

this.EditBox.UpdateDocumentBindings();
Run Code Online (Sandbox Code Playgroud)

x:name 属性很有价值。

这些都可以在源代码中找到。

如果您能更清楚地了解您的项目是如何安排的,我可以提供更多详细信息。但对于初学者来说,我会这样做。更密切地关注所提供的示例。