Binding xaml to RichTextBox

2 posts, 0 answers
  1. gordon
    gordon avatar
    22 posts
    Member since:
    Oct 2015

    Posted 03 Dec 2017 Link to this post

    I'm trying to bind xaml to a RichTextBox.  I have the Edited_WPF sdk sample.  I cannot get the RichTextBox to display my xaml.  Here's what I did.

    Run the sdk sample.

    Type, "This is a test" in the RichTextBox.

    Click "Show XAML"

    Copy the xaml.

    In ExampleDataContext.cs, set private string xamlData = <t:RadDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:t="clr-namespace:Telerik.Windows.Documents.Model;assembly=Telerik.Windows.Documents" xmlns:s="clr-namespace:Telerik.Windows.Documents.Model.Styles;assembly=Telerik.Windows.Documents" xmlns:r="clr-namespace:Telerik.Windows.Documents.Model.Revisions;assembly=Telerik.Windows.Documents" xmlns:n="clr-namespace:Telerik.Windows.Documents.Model.Notes;assembly=Telerik.Windows.Documents" xmlns:th="clr-namespace:Telerik.Windows.Documents.Model.Themes;assembly=Telerik.Windows.Documents" version="1.4" LayoutMode="Flow" LineSpacing="1.15" LineSpacingType="Auto" ParagraphDefaultSpacingAfter="12" ParagraphDefaultSpacingBefore="0" StyleName="defaultDocumentStyle">
      <t:RadDocument.Captions>
        <t:CaptionDefinition IsDefault="True" IsLinkedToHeading="False" Label="Figure" LinkedHeadingLevel="0" NumberingFormat="Arabic" SeparatorType="Hyphen" />
        <t:CaptionDefinition IsDefault="True" IsLinkedToHeading="False" Label="Table" LinkedHeadingLevel="0" NumberingFormat="Arabic" SeparatorType="Hyphen" />
      </t:RadDocument.Captions>
      <t:RadDocument.ProtectionSettings>
        <t:DocumentProtectionSettings EnableDocumentProtection="False" Enforce="False" HashingAlgorithm="None" HashingSpinCount="0" ProtectionMode="ReadOnly" />
      </t:RadDocument.ProtectionSettings>
      <t:RadDocument.Styles>
        <s:StyleDefinition DisplayName="defaultDocumentStyle" IsCustom="False" IsDefault="False" IsPrimary="True" Name="defaultDocumentStyle" Type="Default">
          <s:StyleDefinition.ParagraphStyle>
            <s:ParagraphProperties LineSpacing="1.15" SpacingAfter="12" />
          </s:StyleDefinition.ParagraphStyle>
          <s:StyleDefinition.SpanStyle>
            <s:SpanProperties FontFamily="Verdana" FontSize="16" FontStyle="Normal" FontWeight="Normal" />
          </s:StyleDefinition.SpanStyle>
        </s:StyleDefinition>
        <s:StyleDefinition DisplayName="Normal" IsCustom="False" IsDefault="True" IsPrimary="True" Name="Normal" Type="Paragraph" UIPriority="0" />
        <s:StyleDefinition DisplayName="Table Normal" IsCustom="False" IsDefault="True" IsPrimary="False" Name="TableNormal" Type="Table" UIPriority="59">
          <s:StyleDefinition.TableStyle>
            <s:TableProperties CellPadding="5,0,5,0">
              <s:TableProperties.TableLook>
                <t:TableLook />
              </s:TableProperties.TableLook>
            </s:TableProperties>
          </s:StyleDefinition.TableStyle>
        </s:StyleDefinition>
      </t:RadDocument.Styles>
      <t:Section>
        <t:Paragraph>
          <t:Span Text="This is a test." />
        </t:Paragraph>
      </t:Section>
    </t:RadDocument>

     

    with proper quoting.

    Run the sdk sample, and I get an empty RichTextBox.

    What am I doing wrong?  Thanks.

  2. gordon
    gordon avatar
    22 posts
    Member since:
    Oct 2015

    Posted 03 Dec 2017 in reply to gordon Link to this post

    I figured it out.  The xaml was bad.  I stripped it to:

     

            private string xamlData = @"<t:RadDocument xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:t=""clr-namespace:Telerik.Windows.Documents.Model;assembly=Telerik.Windows.Documents"" xmlns:s=""clr-namespace:Telerik.Windows.Documents.Model.Styles;assembly=Telerik.Windows.Documents"" xmlns:r=""clr-namespace:Telerik.Windows.Documents.Model.Revisions;assembly=Telerik.Windows.Documents"" xmlns:n=""clr-namespace:Telerik.Windows.Documents.Model.Notes;assembly=Telerik.Windows.Documents"" xmlns:th=""clr-namespace:Telerik.Windows.Documents.Model.Themes;assembly=Telerik.Windows.Documents"" version=""1.4"" LayoutMode=""Flow"" LineSpacing=""1.15"" LineSpacingType=""Auto"" ParagraphDefaultSpacingAfter=""12"" ParagraphDefaultSpacingBefore=""0"" StyleName=""defaultDocumentStyle"">
      <t:Section>
        <t:Paragraph>
          <t:Span Text = ""This is a test"" />
        </t:Paragraph>
      </t:Section>
    </t:RadDocument>";

     

    and now the binding is working.

Back to Top