Binding the content of RichTextbox in xaml not working!

3 posts, 0 answers
  1. Ankit
    Ankit avatar
    9 posts
    Member since:
    Jan 2011

    Posted 08 May 2011 Link to this post

    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. Boby
    Admin
    Boby avatar
    763 posts

    Posted 11 May 2011 Link to this post

    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
  3. Ankit
    Ankit avatar
    9 posts
    Member since:
    Jan 2011

    Posted 11 May 2011 Link to this post

    Hi,

    I don't know what you are telling but if I just set the Mode to TwoWay in my DataTemplate it worked!
Back to Top