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

[Solved] Proper Binding of XAML data

4 Answers 159 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard Ellis
Top achievements
Rank 1
Richard Ellis asked on 29 Jul 2011, 11:29 AM
I have XAML data which was generated by splitting up a single Word document into multiple RadDocuments (using manual page breaks) which were then exported seperate XAML documents (in byte arrays).  I then try and dynamically load these XAML byte[] into a RadRichTextBox only to have nothing displayed and no changes written back to the byte array when edited in the editor.

XAML:
<controls:ChildWindow x:Class="CMSPrototype.Controls.TestWindow"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
           xmlns:telerikXAML="clr-namespace:Telerik.Windows.Documents.FormatProviders.Xaml;assembly=Telerik.Windows.Documents.FormatProviders.Xaml"
           Width="400" Height="300"
           Title="TestWindow"
           x:Name="testWindow">
 
    <controls:ChildWindow.Resources>
        <!-- Telerik Data Provider -->
        <telerikXAML:XamlDataProvider x:Key="xamlDataProvider"
            RichTextBox="{Binding ElementName=editor}"
            Xaml="{Binding Path=CurrentDocument, ElementName=testWindow, Mode=TwoWay}"
                                      SetupDocument="XamlDataProvider_SetupDocument"/>
    </controls:ChildWindow.Resources>
 
    <Grid x:Name="LayoutRoot" Margin="2">
 
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
 
        <telerik:RadRichTextBox Name="editor" />
         
        <Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
        <Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />
    </Grid>
</controls:ChildWindow>

Code behind:
using System.Windows;
using System.Windows.Controls;
using Telerik.Windows.Documents.Model;
using Telerik.Windows.Documents.FormatProviders.Xaml;
 
namespace CMSPrototype.Controls
{
    public partial class TestWindow : ChildWindow
    {
        public static readonly DependencyProperty CurrentDocumentProperty = DependencyProperty.RegisterAttached(
                "CurrentDocument",
                typeof(byte[]),
                typeof(TestWindow),
                null
            );
 
        public byte[] CurrentDocument
        {
            get { return (byte[])GetValue(CurrentDocumentProperty); }
            set { SetValue(CurrentDocumentProperty, value); }
        }
         
        public TestWindow(byte[] currentDocument)
        {
            this.CurrentDocument = currentDocument;
            InitializeComponent();
        }
 
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }
 
        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
 
        private void XamlDataProvider_SetupDocument(object sender, Telerik.Windows.Documents.FormatProviders.SetupDocumentEventArgs e)
        {
 
        }
    }
}

RadDocument XAML passed in:
<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.1" DefaultPageLayoutSettings="793.7333,1122.533" LayoutMode="Paged" PageViewMargin="10,10" SectionDefaultPageMargin="95,95,95,95">
  <t:Section PageMargin="120,96,120,96">
    <t:Paragraph FontSize="13.3333330154419" SpacingAfter="0" />
    <t:Paragraph SpacingAfter="0">
      <t:Span FontFamily="Times New Roman" FontSize="16" FontWeight="Bold" Text="All You Need Is Love Lyrics" UnderlineColor="#FF000000" UnderlineDecoration="None" />
      <t:Span FontFamily="Times New Roman" FontSize="16" Text="¬Artist(Band):" UnderlineColor="#FF000000" UnderlineDecoration="None" />
      <t:Span FontFamily="Times New Roman" FontSize="16" FontWeight="Bold" Text="The Beatles" UnderlineColor="#FF000000" UnderlineDecoration="None" />
      <t:Span FontFamily="Times New Roman" FontSize="16" Text=" " UnderlineColor="#FF000000" UnderlineDecoration="None" />
    </t:Paragraph>
    <t:Paragraph SpacingAfter="0">
      <t:Span FontFamily="Times New Roman" FontSize="16" Text="Love, Love, Love.¬Love, Love, Love.¬Love, Love, Love.¬¬There's nothing you can do that can't be done.¬Nothing you can sing that can't be sung.¬Nothing you can say but you can learn how to play the game.¬It's easy.¬¬Nothing you can make that can't be made.¬No one you can save that can't be saved.¬Nothing you can do but you can learn how to be you in time.¬It's easy.¬¬All you need is love.¬All you need is love.¬All you need is love, love.¬Love is all you need.¬¬All you need is love.¬All you need is love.¬All you need is love, love.¬Love is all you need.¬¬Nothing you can know that isn't known.¬Nothing you can see that isn't shown.¬Nowhere you can be that isn't where you're meant to be.¬It's easy.¬¬All you need is love.¬All you need is love.¬All you need is love, love.¬Love is all you need.¬¬All you need is love (All together, now!)¬All you need is love. (Everybody!)¬All you need is love, love.¬Love is all you need (love is all you need)¬(love is all you need) (love is all you need) ¬(love is all you need) Yesterday (love is all you need)¬(love is all you need) (love is all you need)¬¬Yee-hai!¬Oh yeah!¬love is all you need, love is all you need,love is all you need, love is all you need, oh yeah oh hell yea! love is all you need love is all you need love is all you need." UnderlineColor="#FF000000" UnderlineDecoration="None" />
    </t:Paragraph>
  </t:Section>
</t:RadDocument>


What am I doing wrong?

Note:- It works fine if populated by setting the Document property to the output of XamlFormatProvider.Export(byte[]).

4 Answers, 1 is accepted

Sort by
0
Vesko
Telerik team
answered on 03 Aug 2011, 09:26 AM
Hello Richard Ellis,

Thanks for your question. Unfortunately it did not become clear to us what is the exact problem you are experiencing - problem with splitting the document, with import/export from/to XAML, or something else?

It will be very helpful if you send us a small sample application which isolates the problem.

All the best,
Vesko
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Richard Ellis
Top achievements
Rank 1
answered on 03 Aug 2011, 09:37 AM
It should be fairly simple (the splitting of the Document can largely be ignored - it's only important if it turns out there's an issue with the resulting RadDocuments which are created) - I have a ChildWindow containing a RadRichTextbox which is then being bound to a XAML string using a XamlDataProvider as shown in the various Code snippets below.  However the Document is not being shown in the RadRichTextbox and no changes are being written back to the original byte[] representing the Xaml.

How can I get this to work?
0
Richard Ellis
Top achievements
Rank 1
answered on 03 Aug 2011, 09:56 AM
OK.  Looks like it's my binding to a byte[] instead of a string.  Still can't get 2-way binding to work but still a step in the right direction.  It's my fault for assuming the byte[] (which we save to a database) which works with the FormatProvider would automatically work with the DataProvider.
0
Richard Ellis
Top achievements
Rank 1
answered on 03 Aug 2011, 10:27 AM
All working now.  It was definitely my use of a byte[].  Will move everything towards strings now and only convert to byte[] for saving to DB.

Cheers Anyway.
Tags
RichTextBox
Asked by
Richard Ellis
Top achievements
Rank 1
Answers by
Vesko
Telerik team
Richard Ellis
Top achievements
Rank 1
Share this question
or