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

Problem with changing document at runtime

3 Answers 97 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 06 Dec 2010, 02:01 PM
Hello,
I have RadGridView and RichTextBox. After selecting new row in grid I load HTML document into RichTextBox. I found situation when after second selection change I always receive an error. Do you have any suggestions what am I doing wrong?

Error:
Unhandled Error in Silverlight Application
Code: 4004    
Category: ManagedRuntimeError       
Message: System.InvalidCastException: Unable to cast object of type 'Telerik.Windows.Documents.Layout.ParagraphLayoutBox' to type 'Telerik.Windows.Documents.Layout.TableLayoutBox'.
   w Telerik.Windows.Documents.Layout.TableRowLayoutBox.MeasureOverride(SizeF availableSize)
   w Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize)
   w Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize)
   w Telerik.Windows.Documents.Layout.LayoutElement.Arrange(RectangleF finalRect)
   w Telerik.Windows.Documents.Layout.TableLayoutBox.ArrangeOverride(SizeF finalSize)
   w Telerik.Windows.Documents.Layout.LayoutElement.ArrangeCore(RectangleF finalRect)
   w Telerik.Windows.Documents.Layout.LayoutElement.Arrange(RectangleF finalRect)
   w Telerik.Windows.Documents.Layout.SectionLayoutBox.ArrangeOverride(SizeF finalSize)
   w Telerik.Windows.Documents.Layout.LayoutElement.ArrangeCore(RectangleF finalRect)
   w Telerik.Windows.Documents.Layout.LayoutElement.Arrange(RectangleF finalRect)
   w Telerik.Windows.Documents.Layout.DocumentLayoutBox.ArrangeTask.ArrangeCallback(Object state)
   w System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   w System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   w System.Threading.ThreadPoolWorkQueue.Dispatch()
   w System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Code:
void GetDataCompleted(string html)
{
   richTextBox.Document = html.Import(html);
 
   richTextBox.ChangeLayoutMode(LayoutMode);
 
   if (richTextBox.Document.Sections.Count > 0)
       richTextBox.ChangeSectionMargin(new   Telerik.Windows.Documents.Layout.Padding(Margins.left, Margins.top, Margins.right, Margins.bottom));
                     
   richTextBox.Background = new SolidColorBrush(Background);
   richTextBox.Resources = new ResourceDictionary();
 
   Style webLayoutStyle = new Style(typeof(DocumentWebLayoutPresenter));
   webLayoutStyle.Setters.Add(new Setter(DocumentWebLayoutPresenter.BackgroundProperty, Background));
   richTextBox.Resources.Add(typeof(DocumentWebLayoutPresenter), webLayoutStyle);
    
   Style printLayoutStyle = new Style(typeof(DocumentPrintLayoutPresenter));
   printLayoutStyle.Setters.Add(new Setter(DocumentPrintLayoutPresenter.BackgroundProperty, Background));                  
   richTextBox.Resources.Add(typeof(DocumentPrintLayoutPresenter), printLayoutStyle);
                     
   richTextBox.UpdateEditorLayout();
}

3 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 08 Dec 2010, 02:07 PM
Hello Andrew,

I could not reproduce your issue, but it doesn't seem to me that it has anything to do with the code you have provided. (Is "html.Import(html);" working?)
We might be able to provide you with better assistance, if you could elaborate a little bit more on your whole scenario and implementation. We need to take a look at a sample document that causes this issue. A small demo illustrating the scenario would be the best way to get us started. (You can send it in a support ticket)

Regards,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Andrew
Top achievements
Rank 1
answered on 10 Dec 2010, 08:23 AM

Hello,

I found the problem. It’s the width of the window with RichTextBox and specific HTML document (more precisely it’s the length of that document). To reproduce this error use HTML:

<table><tr><td><b>User name:</b></td><td>User</td><td><b>Number:</b></td><td>fcab02ac-1ab4-4e9d-a9e7-2976dfd00129</td></tr></table>

Create RadWindow with your own Show method:

public void Show(string html)
{
     if (this.ActualWidth < 520 || ActualHeight < 600)
     {
          // If width is set to something bigger then 520 - program crashes!!!!
          this.Width = 520;
          this.Height = 600;
     }
   
     try
     {
          HtmlFormatProvider htmlProv = new HtmlFormatProvider();
          rrtbHtml.Document = htmlProv.Import(html);
     }
     catch (Exception ex)
     {
          MessageBox.Show(ex.Message);
     }
   
     this.ShowDialog();
}

Then open this window with html shown above.
Like I said in comment – when width of the window is bigger then 520, program crashes.

I create HTML document dynamically so I can’t be sure that it won’t crash my program.
0
Iva Toteva
Telerik team
answered on 11 Dec 2010, 09:18 AM
Hello Andrew,

Thank you for getting back to us with such a detailed description of how we can reproduce the issue. There indeed seems to be a bug. We will look into the matter and hopefully, we will manage to fix it for the Service Pack next week.
In appreciation of your involvement, the Telerik points in your account have been updated.

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