WPF Richtextbox Bindable in .net 4.5
Asked Answered
E

1

10

So I'm trying to use David Veeneman's Bindable WPF RichTextBox here in my .net 4.5 project. After adding the control and the ValueConverter in my code I noticed only the the public object Convert() will be triggered but the public object ConvertBack() not.

After reading the comments to this project I changed following parts of the control source code.

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;
} 

And this Event Handler:

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

    // Changed:
    Document = TextBox.Document;
}

Now the the both method of the ValueConverter worked fine but events like private void OnNormalTextClick(object sender, RoutedEventArgs e) causes a FatalExecutionEngineError on Runtime.

So i wonder if there are major changes form WPF 3.5 to 4.5?

Or anybody have an idea to work around this?


Update

Binding in XAML

<uc:FsRichTextBox Margin="5"
    Document="{Binding Path=Ereignis.Bericht, 
    Converter={StaticResource flowDocumentConverter}, 
    UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" />
Execrate answered 4/11, 2015 at 9:20 Comment(3)
can you just show how you make the binding please ?Limit
Have you installed .NET framework 4.6 (even if you target 4.5)? Are your trying in Release or Debug? Also, I can't reproduce on by box with the demo and your changes, do you have a full repro code?Testosterone
@SimonMourier At my current development machine is .NET 4.5.1 installed. Target still 4.5Execrate
J
0

I ran the demo you linked here in VS2015 with target framework 4.0 and 4.5. It will not update when I take out the two way data binding.

Add to your RTB. Two way data binding and a name:

Mode=TwoWay 
x:Name="EditBox" 

I think rather than managing the text change yourself here, remove this:

// Changed:
Document = TextBox.Document;

Use an event handler to update the data.

Then in your event handler that is managing your updates (I am assuming a button click? And allow this to manage the update.

this.EditBox.UpdateDocumentBindings();

The x:name attribute is valuable.

This is all found in the source code.

If you can be more clear about how your project is arranged I can provide more detail. But for starters, I would do this. Stick more closely to the provided example.

Juggler answered 9/11, 2015 at 16:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.