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

RitchTextBox and F2 key press

Mar 11, 2011 at 1:02 PM
Edited Mar 11, 2011 at 2:17 PM

Hi All,

When having focus in a RTB, if i click F2 and then move away from the RTB, the RTB displays raw XAML text (<Section...). Is this expected behaviour?


Mar 11, 2011 at 2:47 PM
Edited Mar 11, 2011 at 2:48 PM

I am assuming you are using this inside a DataGridTemplateColumn.  The CellTemplate is probably a TextBlock, and the EditingTemplate is the RTB.  I am guessing that you are binding the TextBlock.Text to the same property you are binding the RTB.Text.  So when you are done editing the text and end edit is called on the DataGrid, the TextBlock now shows the text that was just edited.  But the text is in RTF, therefore, the TextBlock will show it exactly as-is.

To summarize, this is not a problem with the RTB.  My recommendation would be to set the CellTemplate to a readonly RTB.

Mar 11, 2011 at 3:36 PM

Hi Brian,

Many thanks for your prompt response. I am now more confused! I totally thought it was intended behaviour for the extended RTB.


Here is the definition of the datagridtemplate column. I have only defined a RTB

 <dg:DataGridTemplateColumn Header="Notes" Width="*">
                                                    <extToolkit:RichTextBox x:Name="rtbNotes" TextChanged="rtbNotes_TextChanged_1" MaxHeight="150" ScrollViewer.VerticalScrollBarVisibility="Auto" IsReadOnly="{Binding Path=IsReadOnly,Mode=TwoWay}" Text="{Binding PATextNotes,UpdateSourceTrigger=PropertyChanged}" PreviewKeyDown="rtbNotes_PreviewKeyDown" >
                                                            <extToolkit:XamlFormatter />
                                                            <CommandBinding Command="EditingCommands.ToggleBold"/>
                                                            <CommandBinding Command="EditingCommands.ToggleItalic"/>
                                                            <CommandBinding Command="EditingCommands.ToggleUnderline"/>

Workaround: In the previewkeydown event of the RTB I catch the F2 key press and cancel it ( handle=true,)

Mar 11, 2011 at 3:56 PM
Edited Mar 11, 2011 at 3:57 PM

I copied and pasted exactly what you have, but I cannot duplicate your issue.  Do you have any code in the TextChanged event that could be causing the problem?

Mar 11, 2011 at 4:06 PM

I do indeed, but i should really  remove it ...


        TextPointer tp;
        private void rtbNotes_TextChanged_1(object sender, TextChangedEventArgs e)
                System.Windows.Controls.RichTextBox rtb = sender as System.Windows.Controls.RichTextBox;
                tp = rtb.CaretPosition;
{ } }

Mar 11, 2011 at 4:10 PM

I don't know what is causing this behavior.  I would start with a very basic sample.  Remove all command bindings and event handlers.  Make sure there is no code in the setter of the PATextNotes property that could causing the problem.  Let me know what you find.

Mar 11, 2011 at 4:19 PM

I will try that and post back the results. Thanks Brian

Jul 20, 2011 at 11:50 AM

Hi Brian,

I have created a test application that reproduces this problem. I have uploaded the app here (!1117) in case you can have a look.

To repro de problem:

1) Put cursor in the RTB in the first row of the datagrid, and type something, then press F2, now press enter or the down key

The XAML is displayed in the RTB

Hope you can have a look.


Jul 20, 2011 at 2:50 PM

This does not occur in the latest version of  Just download the source code and compile the solution in the Main folder.  Or you can just add e.Handled = true after the InsertText() method call.