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

Error getting document from xaml

6 Answers 135 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
CarlosLima
Top achievements
Rank 1
CarlosLima asked on 18 Nov 2010, 11:15 AM
I have the following serialization created from my xaml code using XamlFormatProvider

<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="816,1056" LayoutMode="Paged" PageViewMargin="10,10" ParagraphDefaultSpacingAfter="10" SectionDefaultPageMargin="95,95,95,95">
  <t:Section PageMargin="96,96,96,96">
    <t:Paragraph SpacingAfter="6.66666650772095" SpacingBefore="6.66666650772095">
      <t:Span FontFamily="Calibri" FontWeight="Bold" Text="Title." />
    </t:Paragraph>
    <t:Paragraph SpacingAfter="6.66666650772095" SpacingBefore="6.66666650772095">
      <t:Span FontFamily="Calibri" Text="text text text " /><telerik:InlineUIContainer xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="20" Style="{x:Null}" Width="80" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
  <telerik:InlineUIContainer.DefaultStyleSettings>
    <Telerik_Windows_Documents_Model_Styles_Telerik_Windows_Documents:StyleDefinition BasedOn="{x:Null}" xmlns:Telerik_Windows_Documents_Model_Styles_Telerik_Windows_Documents="clr-namespace:Telerik.Windows.Documents.Model.Styles;assembly=Telerik.Windows.Documents" />
  </telerik:InlineUIContainer.DefaultStyleSettings>
  <Button Content="Fulano de Tal" FontSize="12" Height="30" HorizontalAlignment="Center" Margin="0,0,0,0" Tag="ID|...   width = numcaracteres * 8" VerticalAlignment="Bottom" Width="80">
    <Button.Background>
      <SolidColorBrush Color="#00FFFFFF" />
    </Button.Background>
    <Button.Foreground>
      <SolidColorBrush Color="#FFFF0000" />
    </Button.Foreground>
    <Button.Style>
      <Style BasedOn="{x:Null}" TargetType="Button">
        <Setter Property="Foreground">
          <Setter.Value>
            <SolidColorBrush Color="#FF000000" />
          </Setter.Value>
        </Setter>
        <Setter Property="Padding">
          <Setter.Value>
            <Thickness>0,0,0,0</Thickness>
          </Setter.Value>
        </Setter>
        <Setter Property="BorderThickness">
          <Setter.Value>
            <Thickness>0,0,0,0</Thickness>
          </Setter.Value>
        </Setter>
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="Button">
              <Grid Margin="0,0,0,0">
                <Border x:Name="Background" Background="{x:Null}" BorderThickness="0,0,0,1" CornerRadius="0,0,0,0">
                  <Border.BorderBrush>
                    <SolidColorBrush Color="#FFFF0000" />
                  </Border.BorderBrush>
                  <Grid Background="{x:Null}" Margin="0,0,0,0">
                    <Border x:Name="BackgroundAnimation" Child="{x:Null}" Opacity="0">
                      <Border.Background>
                        <SolidColorBrush Color="#FF448DCA" />
                      </Border.Background>
                    </Border>
                  </Grid>
                </Border>
                <ContentPresenter x:Name="contentPresenter" Content="{x:Null}" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Bottom" />
                <VisualStateManager.VisualStateGroups>
                  <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal" Storyboard="{x:Null}" />
                    <VisualState x:Name="MouseOver" Storyboard="{x:Null}" />
                    <VisualState x:Name="Pressed" Storyboard="{x:Null}" />
                    <VisualState x:Name="Disabled" Storyboard="{x:Null}" />
                  </VisualStateGroup>
                  <VisualStateGroup x:Name="FocusStates">
                    <VisualState x:Name="Focused" Storyboard="{x:Null}" />
                    <VisualState x:Name="Unfocused" Storyboard="{x:Null}" />
                  </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
              </Grid>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
    </Button.Style>
  </Button>
</telerik:InlineUIContainer><t:Span FontFamily="Calibri" Text=" % (" /><telerik:InlineUIContainer xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="20" Style="{x:Null}" Width="30" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
  <telerik:InlineUIContainer.DefaultStyleSettings>
    <Telerik_Windows_Documents_Model_Styles_Telerik_Windows_Documents:StyleDefinition BasedOn="{x:Null}" xmlns:Telerik_Windows_Documents_Model_Styles_Telerik_Windows_Documents="clr-namespace:Telerik.Windows.Documents.Model.Styles;assembly=Telerik.Windows.Documents" />
  </telerik:InlineUIContainer.DefaultStyleSettings>
  <Button Content="XX" FontSize="12" Height="30" HorizontalAlignment="Center" Margin="0,0,0,0" Tag="ID|...   width = numcaracteres * 8" VerticalAlignment="Bottom" Width="30">
    <Button.Background>
      <SolidColorBrush Color="#00FFFFFF" />
    </Button.Background>
    <Button.Foreground>
      <SolidColorBrush Color="#FFFF0000" />
    </Button.Foreground>
    <Button.Style>
      <Style BasedOn="{x:Null}" TargetType="Button">
        <Setter Property="Foreground">
          <Setter.Value>
            <SolidColorBrush Color="#FF000000" />
          </Setter.Value>
        </Setter>
        <Setter Property="Padding">
          <Setter.Value>
            <Thickness>0,0,0,0</Thickness>
          </Setter.Value>
        </Setter>
        <Setter Property="BorderThickness">
          <Setter.Value>
            <Thickness>0,0,0,0</Thickness>
          </Setter.Value>
        </Setter>
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="Button">
              <Grid Margin="0,0,0,0">
                <Border x:Name="Background" Background="{x:Null}" BorderThickness="0,0,0,1" CornerRadius="0,0,0,0">
                  <Border.BorderBrush>
                    <SolidColorBrush Color="#FFFF0000" />
                  </Border.BorderBrush>
                  <Grid Background="{x:Null}" Margin="0,0,0,0">
                    <Border x:Name="BackgroundAnimation" Child="{x:Null}" Opacity="0">
                      <Border.Background>
                        <SolidColorBrush Color="#FF448DCA" />
                      </Border.Background>
                    </Border>
                  </Grid>
                </Border>
                <ContentPresenter x:Name="contentPresenter" Content="{x:Null}" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Bottom" />
                <VisualStateManager.VisualStateGroups>
                  <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal" Storyboard="{x:Null}" />
                    <VisualState x:Name="MouseOver" Storyboard="{x:Null}" />
                    <VisualState x:Name="Pressed" Storyboard="{x:Null}" />
                    <VisualState x:Name="Disabled" Storyboard="{x:Null}" />
                  </VisualStateGroup>
                  <VisualStateGroup x:Name="FocusStates">
                    <VisualState x:Name="Focused" Storyboard="{x:Null}" />
                    <VisualState x:Name="Unfocused" Storyboard="{x:Null}" />
                  </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
              </Grid>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
    </Button.Style>
  </Button>
</telerik:InlineUIContainer><t:Span FontFamily="Calibri" Text=") text text text." /></t:Paragraph>
    <t:Paragraph SpacingAfter="6.66666650772095" SpacingBefore="6.66666650772095" />
  </t:Section>
</t:RadDocument>

and when i try to get the document from it again I get the following exception:


Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3; .NET4.0E)
Timestamp: Thu, 18 Nov 2010 10:08:51 UTC


Message: Unhandled Error in Silverlight Application
Code: 4004    
Category: ManagedRuntimeError       
Message: System.TypeInitializationException: The type initializer for 'Telerik.Windows.Documents.Layout.RadTextMeasurer' threw an exception. ---> System.UnauthorizedAccessException: Invalid cross-thread access.
   at MS.Internal.XcpImports.CheckThread()
   at System.Windows.DependencyObject..ctor(UInt32 nativeTypeIndex, IntPtr constructDO)
   at System.Windows.Controls.TextBlock..ctor()
   at Telerik.Windows.Documents.Layout.RadTextMeasurer.InitializeMeasureBlock()
   at Telerik.Windows.Documents.Layout.RadTextMeasurer..cctor()
   --- End of inner exception stack trace ---
   at Telerik.Windows.Documents.Layout.RadTextMeasurer.Measure(String text, Span span)
   at Telerik.Windows.Documents.Layout.SpanLayoutBox.MeasureTextOverride()
   at Telerik.Windows.Documents.Layout.SpanLayoutBox.MeasureText()
   at Telerik.Windows.Documents.Layout.SpanLayoutBox.MeasureOverride(SizeF availableSize)
   at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize)
   at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize)
   at Telerik.Windows.Documents.Layout.ParagraphLayoutBox.MeasureOverride(SizeF availableSize)
   at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize)
   at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize)
   at Telerik.Windows.Documents.Layout.SectionLayoutBox.MeasureOverride(SizeF availableSize)
   at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize)
   at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize)
   at Telerik.Windows.Documents.Layout.LayoutElement.Arrange(RectangleF finalRect)
   at Telerik.Windows.Documents.Layout.DocumentLayoutBox.ArrangeTask.ArrangeCallback(Object state)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()     

Line: 56
Char: 13
Code: 0
URI: http://localhost:55603/SilverlightApplication6TestPage.aspx



Is InlineUIContainer supported for serialization or not? Is there a way to have only a few paragraphs or spans editable where others are not?

Thanks

6 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 19 Nov 2010, 05:15 PM
Hi carlos,

The problem seems to lie within the style of the button.
Could you please send us the XAML file you imported initially, so we can see what the problem is?

Kind regards,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
CarlosLima
Top achievements
Rank 1
answered on 19 Nov 2010, 05:43 PM
Hi.
I don't have it anymore since i've changed the code to hyperlinkbutton but used to have the same error with it as long as I did:

private

 

 

void Page_Loaded(object sender, RoutedEventArgs e)

 

{
xmlContract = well formed xaml code...

Editor.Document =

 

Utils.GetDocumentFromXaml(xmlContract);

 

Editor.Document.UpdateLayout();

}

Once i removed the line

Editor.Document.UpdateLayout();
It worked fine...
Anyway I still have an issue. If i change the width (programmatically somewhere along the code) of the inlinecontainer which contains the hyperlinkbutton and then i call

 

Editor.Document.UpdateLayout();
It doesn't update it's width.. should I call

 

container.UiElement.UpdateLayout();
instead or first?

Thanks

0
CarlosLima
Top achievements
Rank 1
answered on 19 Nov 2010, 06:48 PM
Apparently container.UiElement.UpdateLayout(); solved it... so what it document.updatelayout() supposed to do?

Just another question:
I would like to place some buttons on the xaml for printing the document and saving it to pdf. The only samples of code that i found where using the ui toolbar. Is there any other way of doing it? Can you give me an example?

Thanks
0
CarlosLima
Top achievements
Rank 1
answered on 20 Nov 2010, 08:40 PM
UpdateEditorLayout();... my mistake.

I really need a way to programmatically save the document to docx and pdf. Is there any way of doing it? I found that RichTextBox has a Print method but not a Save one.

Thanks.
0
CarlosLima
Top achievements
Rank 1
answered on 20 Nov 2010, 09:20 PM
Got it.... http://www.telerik.com/help/silverlight/radrichtextbox-features-import-export.html
I was using the code provided on the site but was having an exception with "user initiated dialog.." Apparently we can't have breakpoints there..

Thanks anyway.
0
Iva Toteva
Telerik team
answered on 23 Nov 2010, 06:00 PM
Hi carlos,

We are glad to hear that you have solved the problems you encountered by yourself.
If you meet any other difficulties, do not hesitate to contact us again.

Greetings,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
RichTextBox
Asked by
CarlosLima
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
CarlosLima
Top achievements
Rank 1
Share this question
or