C#从一个网格中删除控件并将其添加到另一个网格

时间:2014-08-19 17:42:27

标签: c# wpf telerik

我有一个来自Telerik的重型控件--RadRichTextBox,加载时需要很长时间。我是在应用程序启动时创建的,我在不同的地方添加和删除它。

if (gridG.Children.Contains(textEditControl))
   gridG.Children.Remove(textEditControl);

if (!gridG.Children.Contains(textEditControl))
   gridG.Children.Add(textEditControl);

我还会在删除之前备份它的内容,并在必要时添加后恢复。

网格在弹出窗口内。

问题是我收到了错误。它发生在打开弹出窗口后,在网格之间切换几次RRTB,关闭它并再次打开 - 然后我收到了这个错误:

at Telerik.Windows.Documents.Layout.LayoutElement.SetParent(LayoutElement newParent)
   at Telerik.Windows.Documents.Layout.LayoutBox.get_Parent()
   at Telerik.Windows.Documents.DocumentPosition.GetCurrentTableCellBox()
   at Telerik.Windows.Documents.DocumentPosition.GetCurrentTableRowBox()
   at Telerik.Windows.Documents.DocumentPosition.GetCurrentTableBox()
   at Telerik.Windows.Controls.RichTextBoxUI.TableStylesGallery.TrySetSelectedTableStyle()
   at Telerik.Windows.Controls.RichTextBoxUI.TableStylesGallery.CaretPosition_PositionChanged(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at Telerik.Windows.Documents.DocumentPosition.OnPositionChanged()
   at Telerik.Windows.Documents.Utils.SuspendChangingAndChangedActionCounter.InvokeChangedActionInternal()
   at Telerik.Windows.Documents.Utils.SuspendChangingAndChangedActionCounter.InvokeChanged()
   at Telerik.Windows.Documents.DocumentPosition.CallOnPositionChanged(Boolean changesCursorInitialLocation)
   at Telerik.Windows.Documents.DocumentPosition.Reset()
   at Telerik.Windows.Documents.Model.RadDocument.Measure(SizeF measureSize)
   at Telerik.Windows.Documents.UI.DocumentWebLayoutPresenter.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.UIElement.UpdateLayout()
   at Telerik.Windows.Documents.UI.DocumentPresenterBase.Telerik.Windows.Controls.IDocumentEditorPresenter.UpdateLayout()
   at Telerik.Windows.Controls.RadRichTextBox.<>c__DisplayClass1e.<UpdateEditorLayout>b__1d()
   at Telerik.Windows.Controls.RadRichTextBox.UpdateEditorLayout(Boolean focusCarret, Boolean updateCaretSize, Boolean async)
   at Telerik.Windows.Controls.RadRichTextBox.UpdateEditorLayout(Boolean async)
   at Telerik.Windows.Controls.RadRichTextBox.UpdateEditorLayout()
   at Telerik.Windows.Controls.RichTextBoxUI.Dialogs.Styles.ObservableStyleCollection..ctor(RadDocument document, RadRichTextBox snapshotRichtextBox, Int32 snapshotWidth, Int32 snapshotHeight, Boolean addClearAllStyle, Boolean onlyPrimary)
   at Telerik.Windows.Controls.RichTextBoxUI.StylesGallery.SetInitialQuickStyleItemSource(RadRichTextBox radRichTextBox)
   at Telerik.Windows.Controls.RichTextBoxUI.StylesGallery.<>c__DisplayClass1.<SetQuickStyleItemSource>b__0()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

我试图把所有东西放在try / catch块中,但它没有用。也许在Telerik的库中会抛出一些异常。

我该怎么做才能解决这个问题?

0 个答案:

没有答案