This project has moved. For the latest updates, please go here.

RichTextBox not working in DataTemplate

Jan 12, 2011 at 11:46 AM

I am trying to use RichTextBox in a DataTemplate of a ListView/GridView, to show the RichText. I am using the XamTextFormatter as i have data stored as Xaml. My data template looks like as below...

<ListView ItemsSource="{Binding CommentCollection}">

<ListView.ItemTemplate>

<DataTemplate>

<ext:RichTextBox Height=60 Text="{Binding Comment}">

<ext:RichTextBox.TextFormatter>

<ext:XamTextFormatter />

</ext:RichTextBox.TextFormatter>

</ext:RichTextBox>

</DataTemplate>

</ListView.ItemTemplate>

</ListView>

 

Please let me know, if RichTextBox really works with DataTemplate with XamTextFormatter or am i missing something?

Jan 12, 2011 at 3:00 PM

Yes, it works.  How is it not working for you?  Are you getting an error?

Jan 13, 2011 at 1:59 AM

I'm not getting any error but for me it shows the data in plain XAML, rather than the RichText.

Will it be possible that you provide me a small sample?

Thanks.

Jan 13, 2011 at 7:49 PM
Edited Jan 13, 2011 at 7:50 PM

@pappu 

 

Use RtfFormatter.cs not XamlFormatter.cs.

Jan 13, 2011 at 7:58 PM

Thanks LisaTatum, I have been swamped.  By the way the RtfFormatter is the default formatter, so there is no need to define a TextFormatter in your xaml.

Jan 14, 2011 at 2:03 AM

Lisa & Brian, As i mentioned earlier that my data in database/ViewModel is in XAML Format. So, i don't think that using a RtfFormatter instead of XAMLFormatter will render the RichText correctly. On the other hand, if it works with RtfFormatter then why not with XAMLFormatter?

In case, RichTextBox in DataTemplate works only with RtfFormatter is there a way to render the xamlformatted Text in RTF by using some converter in XAML?

Jan 14, 2011 at 2:25 PM

I will look into this tonight.  Can you provide some sample text that you are loading?

Jan 18, 2011 at 2:04 AM
Hello Brian,
Below are some sample text for XAML...
1) <Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="LeftToRight" NumberSubstitution.CultureSource="User" NumberSubstitution.Substitution="AsCulture" FontFamily="tahoma" FontStyle="Normal" FontWeight="Normal" FontStretch="Normal" FontSize="10" Foreground="#FF000000" Typography.StandardLigatures="True" Typography.ContextualLigatures="True" Typography.DiscretionaryLigatures="False" Typography.HistoricalLigatures="False" Typography.AnnotationAlternates="0" Typography.ContextualAlternates="True" Typography.HistoricalForms="False" Typography.Kerning="True" Typography.CapitalSpacing="False" Typography.CaseSensitiveForms="False" Typography.StylisticSet1="False" Typography.StylisticSet2="False" Typography.StylisticSet3="False" Typography.StylisticSet4="False" Typography.StylisticSet5="False" Typography.StylisticSet6="False" Typography.StylisticSet7="False" Typography.StylisticSet8="False" Typography.StylisticSet9="False" Typography.StylisticSet10="False" Typography.StylisticSet11="False" Typography.StylisticSet12="False" Typography.StylisticSet13="False" Typography.StylisticSet14="False" Typography.StylisticSet15="False" Typography.StylisticSet16="False" Typography.StylisticSet17="False" Typography.StylisticSet18="False" Typography.StylisticSet19="False" Typography.StylisticSet20="False" Typography.Fraction="Normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.EastAsianExpertForms="False" Typography.Variants="Normal" Typography.Capitals="Normal" Typography.NumeralStyle="Normal" Typography.NumeralAlignment="Normal" Typography.EastAsianWidths="Normal" Typography.EastAsianLanguage="Normal" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.StylisticAlternates="0"><Paragraph><Run>Broadway Comment saved</Run></Paragraph></Section>
2) <Section FontSize="10" IsHyphenationEnabled="False" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph><Run>Broadway Comment saved now</Run></Paragraph></Section>
3) <Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="LeftToRight" NumberSubstitution.CultureSource="User" NumberSubstitution.Substitution="AsCulture" FontFamily="Microsoft Sans Serif" FontStyle="Normal" FontWeight="Normal" FontStretch="Normal" FontSize="10" Foreground="#FF000000" Typography.StandardLigatures="True" Typography.ContextualLigatures="True" Typography.DiscretionaryLigatures="False" Typography.HistoricalLigatures="False" Typography.AnnotationAlternates="0" Typography.ContextualAlternates="True" Typography.HistoricalForms="False" Typography.Kerning="True" Typography.CapitalSpacing="False" Typography.CaseSensitiveForms="False" Typography.StylisticSet1="False" Typography.StylisticSet2="False" Typography.StylisticSet3="False" Typography.StylisticSet4="False" Typography.StylisticSet5="False" Typography.StylisticSet6="False" Typography.StylisticSet7="False" Typography.StylisticSet8="False" Typography.StylisticSet9="False" Typography.StylisticSet10="False" Typography.StylisticSet11="False" Typography.StylisticSet12="False" Typography.StylisticSet13="False" Typography.StylisticSet14="False" Typography.StylisticSet15="False" Typography.StylisticSet16="False" Typography.StylisticSet17="False" Typography.StylisticSet18="False" Typography.StylisticSet19="False" Typography.StylisticSet20="False" Typography.Fraction="Normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.EastAsianExpertForms="False" Typography.Variants="Normal" Typography.Capitals="Normal" Typography.NumeralStyle="Normal" Typography.NumeralAlignment="Normal" Typography.EastAsianWidths="Normal" Typography.EastAsianLanguage="Normal" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.StylisticAlternates="0"><Paragraph FontFamily="tahoma"><Run>This comment is  generated again for Center </Run><Run FontWeight="Bold">Structured </Run><Run>Mall. -----------------------</Run></Paragraph></Section>
Please let me know if you need more samples.
Thanks.
Jan 21, 2011 at 3:51 PM

Okay, I have it fixed.  This is actually a bug that was fixed and that I re-introduced.  Download the latest source code to get the fix.

Jan 24, 2011 at 8:29 AM

Hi Brian, I'm still not able to see the DataTemplate thing working.

I copied your changes of Setter in TextFormatter and tried to use with the DataTemplate. But, as soon as my ViewModel DataContext gets populated the RichTextBox's OnTextPropertyChanged method gets called with e.NewValue="Text". However, i have no idea from where its coming up. It does not exists in my Viewmodel datacontext. Following is the DataTemplate used by me.

<extToolkit:RichTextBox Height="{TemplateBinding Height}" BorderThickness="0" IsReadOnly="False" VerticalScrollBarVisibility="Visible" Text="{TemplateBinding Content}">
                        <extToolkit:RichTextBox.TextFormatter>
                            <extToolkit:XamlFormatter/>
                        </extToolkit:RichTextBox.TextFormatter>
                        <extToolkit:RichTextBox.Resources>
                            <Style TargetType="{x:Type Paragraph}">
                                <Setter Property="Margin" Value="0"/>
                            </Style>
                        </extToolkit:RichTextBox.Resources>
                    </extToolkit:RichTextBox>

Please let me know, in case i'm missing something.

 

 

Jan 24, 2011 at 9:55 AM

Brian, It works with ListView.GridView data template. The above template, i was trying with Infragistic Grid. So seems an issue with the Infragistic Grid.

So, Please ignore the above comment.

Thanks for the bug fix!!!