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

Binding xaml to RichTextBox

1 Answer 148 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
gordon
Top achievements
Rank 1
gordon asked on 03 Dec 2017, 07:19 PM

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.

1 Answer, 1 is accepted

Sort by
0
gordon
Top achievements
Rank 1
answered on 03 Dec 2017, 08:39 PM

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.

Tags
RichTextBox
Asked by
gordon
Top achievements
Rank 1
Answers by
gordon
Top achievements
Rank 1
Share this question
or