This is a migrated thread and some comments may be shown as answers.

Binding the content of RichTextbox in xaml not working!

2 Answers 101 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Ankit
Top achievements
Rank 1
Ankit asked on 09 May 2011, 04:45 AM
Hello,

This is my DataTemplate:-

<DataTemplate x:Key="ItemTemplateArticles">
            <Grid Background="White">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition Height="Auto" MinHeight="26"/>
                </Grid.RowDefinitions>
                <telerik:RadRichTextBox x:Name="richArticle" Width="840" Height="100">
                    <telerik:RadRichTextBox.Resources>
                        <telerikXaml:XamlDataProvider x:Key="xamlDataProvider"  RichTextBox="{Binding ElementName=richArticle}" Xaml="{Binding ArticleContent}"  />
                    </telerik:RadRichTextBox.Resources>
                </telerik:RadRichTextBox>
                    <StackPanel Orientation="Horizontal" Grid.Row="1" d:LayoutOverrides="Height" Margin="0,3" HorizontalAlignment="Right">
                    <HyperlinkButton x:Name="hypEdit" Content="Edit" Margin="0" d:LayoutOverrides="Width"/>
                    <HyperlinkButton x:Name="hypRemove" Content="Remove" Margin="3,0,0,0"/>
                </StackPanel>
            </Grid>
        </DataTemplate>

Why can't I see the content in RadRichTextbox? The ArticleContent is a field in my entity. Sample string returned from the database for this field is :-

<t:RadDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:t="clr-namespace:Telerik.Windows.Documents.Model;assembly=Telerik.Windows.Documents" version="1.0" DefaultPageLayoutSettings="800,1140" LayoutMode="Flow" PageViewMargin="0,0" ParagraphDefaultSpacingAfter="0" SectionDefaultPageMargin="6,6,6,6">
  <t:Section>
    <t:Paragraph Background="#00FFFFFF" SpacingAfter="0">
      <t:Span Text="test test test....hello world is this working????" />
    </t:Paragraph>
  </t:Section>
</t:RadDocument>

Can you find any bug in the code? I can see the Edit and Remove hyperlinkbutton in listbox but can't see radrichtextbox's content. Any help?

2 Answers, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 11 May 2011, 01:23 PM
Hi Ankit,
The DataContext property of the elements added to resources is not properly updated by the runtime when their parent's DataContext is changed. To work around this, you should add the xamlDataProvider to the visual tree (it hasn't visual presentation) like this:
<DataTemplate x:Key="ItemTemplateArticles">
    <Grid Background="White">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition Height="Auto" MinHeight="26"/>
        </Grid.RowDefinitions>
        <telerikXaml:XamlDataProvider x:Name="xamlDataProvider"  RichTextBox="{Binding ElementName=richArticle}" Xaml="{Binding ArticleContent}"  />
        <telerik:RadRichTextBox x:Name="richArticle" Width="840" Height="100"/>
        <StackPanel Orientation="Horizontal" Grid.Row="1" d:LayoutOverrides="Height" Margin="0,3" HorizontalAlignment="Right">
            <HyperlinkButton x:Name="hypEdit" Content="Edit" Margin="0" d:LayoutOverrides="Width"/>
            <HyperlinkButton x:Name="hypRemove" Content="Remove" Margin="3,0,0,0"/>
        </StackPanel>
    </Grid>
</DataTemplate>

All the best,
Boby
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ankit
Top achievements
Rank 1
answered on 11 May 2011, 03:59 PM
Hi,

I don't know what you are telling but if I just set the Mode to TwoWay in my DataTemplate it worked!
Tags
RichTextBox
Asked by
Ankit
Top achievements
Rank 1
Answers by
Boby
Telerik team
Ankit
Top achievements
Rank 1
Share this question
or