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

Binding Text in RichTextBox

Nov 21, 2011 at 2:41 PM

Hello!

 

I'm trying to use the RichTextBox in a project of mine. The problem however, is, that I can't figure out how to databind the Text-property.

The documentation explains the binding like this

<toolkit:RichTextBox x:Name="_richTextBox" Grid.Row="1" Margin="10" BorderBrush="Gray" Padding="10"
                                          Text="{Binding Notes}" 
                                          ScrollViewer.VerticalScrollBarVisibility="Auto" />

I have bound the TextBox to a property called Description of type String. When I try to get the value of Description it is just null. How can this be?

Nov 22, 2011 at 2:47 PM

Tang,

I used the following for my implementation.  Maybe this will help.  I used a XAML formatter in my code, but you may have a different requirement and need to use another one or roll your own.

<tk:RichTextBox x:Name="RTB" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="2" Margin="4" BorderBrush="Transparent" Padding="8" BorderThickness="0"  IsEnabled="{Binding Path=CanEdit}"
                            Text="{Binding Path=CurrNote.Content, UpdateSourceTrigger=PropertyChanged}" ScrollViewer.VerticalScrollBarVisibility="Auto" 
                                FontFamily="Segoe UI" FontSize="12" FontWeight="Normal" AcceptsTab="True" AcceptsReturn="True" IsReadOnly="{Binding Path=CurrNote.IsNotAuthor}" IsUndoEnabled="True"
                                SelectionBrush="LightSteelBlue">
                    <tk:RichTextBox.Resources>
                        <Style TargetType="{x:Type Paragraph}">
                            <Setter Property="Margin" Value="0"/>
                        </Style>
                    </tk:RichTextBox.Resources>
                    <tk:RichTextBox.TextFormatter>
                        <tk:XamlFormatter/>
                    </tk:RichTextBox.TextFormatter>
                    <tk:RichTextBoxFormatBarManager.FormatBar>
                        <tk:RichTextBoxFormatBar/>
                    </tk:RichTextBoxFormatBarManager.FormatBar>
                </tk:RichTextBox>

 

Nov 28, 2011 at 3:15 PM

Have you solved your issue?