This project has moved and is read-only. For the latest updates, please go here.

Rich Text Box text only updates on first non-empty value

Jan 4, 2011 at 3:50 PM

I don't know if this is the proper forum for posting general questions such as this, but I'll give it a try anyways cause the following problem has been bugging me for countless hours now. I'm using the rich text box included in the extended WPF Toolkit according to the documentation:

<extToolkit:RichTextBox x:Name="_richTextBox"  Margin="10" BorderBrush="Gray" Padding="10" Text="{Binding Path=ExecutiveSummary, UpdateSourceTrigger=PropertyChanged}"                                           ScrollViewer.VerticalScrollBarVisibility="Auto" />

My problem is that the data binding doesn't update when the data context changes, it only updates the first time I bind to a non-empty value in the database, and then that value stays on the screen. Everything else on the screen that is data bound updates, but not the rich text box. I can save the content back to the database, however. Any ideas what's causing this?

Jan 4, 2011 at 4:54 PM

This is the perfect place to ask your question, and yes this was a bug that was recently discovered by another user.  The good news is that it has been fixed and you can get it in the latest source code download.  There is a planned release in a week, but if you can't wait that long just get the source.

Jan 4, 2011 at 8:01 PM

Thanks! I downloaded the source code and it works! I had to add a custom converter, however, to deal with null values in my database that otherwise generated the following error message: "Unrecognized structure in data format 'Rich Text Format'. Parameter name: stream"

Including my crude converter below (basically just inserted an empty rtf string, i'm sure there are much better ways of accomplishing the same result)

Public Class NullToRTFConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        If value = "" Then
            Return "{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Tahoma;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs24\f2\cf0 \cf0\ql{\f2 {\ltrch }\li0\ri0\s"
        Else
            Return value
        End If
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        If value = "" Then
            Return "{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Tahoma;}}{\colortbl\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs24\f2\cf0 \cf0\ql{\f2 {\ltrch }\li0\ri0\s"
        Else
            Return value
        End If
    End Function
End Class

 

 

Jan 4, 2011 at 8:10 PM

Ahh, I forgot to put that check back in.  That was a bug I fixed a long time ago, and I re-introduced it when I changed the way the Text works.  Basically you can modify the source to check for a null or empty string before setting the text, and just don't set it if it is null or empty.  I will fix this tonight.  Thanks for letting me know.

Jan 4, 2011 at 9:20 PM

Glad to help, thanks for providing a great toolkit!

Jan 7, 2011 at 9:08 PM

was this with the latest source? I am unable to duplicate this issue.  I have defined a property that is initially set to null, but no exception occur.

            private string _Notes = null;
            public string Notes
            {
                get { return _Notes; }
                set
                {
                    _Notes = value;
                    OnPropertyChanged("Notes");
                }
            }

 

<extToolkit:RichTextBox Text="{Binding Notes}" />    
Jan 7, 2011 at 9:29 PM

Actually don't see it in the source code I downloaded this Tuesday.

Jan 8, 2011 at 12:24 AM

Okay, then I will consider this resolved.  If you find anything else be sure to let me know.

Feb 3, 2011 at 5:28 PM

I can confirm this for the XamlTextFormatter on the latest source (wpftoolkit-67703)