2010-10-15 78 views
0

我已經添加了一個依賴項屬性到我的視圖基類,它應該允許子UserControls設置父窗口上的一些屬性,一個是SizeToContent。當我OnSizeToContent方法運行,當其試圖改變從WidthAndHeight主窗口的SizeToContent爲手動,我得到這個奇怪的錯誤:檢測Setting SizeToContent fom Child UserControl cause FatalExecutionEngineError

FatalExecutionEngineError 消息:運行時遇到一個致命錯誤。錯誤的地址是0x58e29ddd,線程0x17e8。錯誤代碼是0x80131623。此錯誤可能是CLR中的錯誤,也可能是用戶代碼中不安全或不可驗證的部分。此錯誤的常見來源包括COM-interop或PInvoke的用戶編組錯誤,這可能會破壞堆棧。

從來沒有見過這個錯誤,我不知道如何調試這個,搜索沒有發現任何相關的。

任何人都可以破譯?

private static void OnSizeToContentChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) 
{ 
    if (Designer.IsInDesignMode) 
      return; 
    ((ViewBase) o).MainWindow.SizeToContent = (SizeToContent) e.NewValue; 
} 

private static readonly DependencyProperty SizeToContentProperty = 
    DependencyProperty.Register("SizeToContent", typeof(SizeToContent), typeof(ViewBase), 
      new UIPropertyMetadata(SizeToContent. WidthAndHeight, OnSizeToContentChanged)); 

這裏的局部堆棧跟蹤OnSizeToContentChanged後:

WindowsBase.dll!MS.Internal.Invariant.FailFast(string message, string detailMessage) + 0x35 bytes 
    WindowsBase.dll!MS.Internal.Invariant.Assert(bool condition) + 0x2b bytes 
    PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.Grid}) + 0xc4 bytes  
    PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.ItemsPresenter}) + 0x158 bytes 
    PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.Border}) + 0x158 bytes 
    PresentationCore.dll!System.Windows.UIElement.PropagateResumeLayout(System.Windows.Media.Visual parent, System.Windows.Media.Visual v = {System.Windows.Controls.ItemsControl}) + 0x158 bytes 
    PresentationCore.dll!System.Windows.Media.Visual.AddVisualChild(System.Windows.Media.Visual child = {System.Windows.Controls.ItemsControl}) + 0x4f bytes  
    PresentationFramework.dll!System.Windows.FrameworkElement.TemplateChild.set(System.Windows.UIElement value) + 0x32 bytes  
    PresentationFramework.dll!System.Windows.Controls.ContentPresenter.UseContentTemplate.BuildVisualTree(System.Windows.FrameworkElement container) + 0xa4 bytes 
    PresentationFramework.dll!System.Windows.StyleHelper.ApplyTemplateContent(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> dataField, System.Windows.DependencyObject container, System.Windows.FrameworkElementFactory templateRoot, int lastChildIndex, System.Collections.Specialized.HybridDictionary childIndexFromChildID, System.Windows.FrameworkTemplate frameworkTemplate) + 0x1c9 bytes 
    PresentationFramework.dll!System.Windows.FrameworkTemplate.ApplyTemplateContent(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> templateDataField, System.Windows.FrameworkElement container = {System.Windows.Controls.ContentPresenter}) + 0x3b bytes 
    PresentationFramework.dll!System.Windows.FrameworkElement.ApplyTemplate() + 0x7b bytes 
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x40 bytes 
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes 
    PresentationFramework.dll!System.Windows.Documents.AdornerDecorator.MeasureOverride(System.Windows.Size constraint) + 0x61 bytes  
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d6 bytes 
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes 
    PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint) + 0x18c bytes  
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d6 bytes 
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes 
    PresentationFramework.dll!System.Windows.Controls.Border.MeasureOverride(System.Windows.Size constraint) + 0x18f bytes 
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x1d6 bytes 
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes 
    PresentationFramework.dll!System.Windows.Window.MeasureOverrideHelper(System.Windows.Size constraint) + 0x14b bytes 
    PresentationFramework.dll!System.Windows.Window.MeasureOverride(System.Windows.Size availableSize) + 0xd6 bytes 
    PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x526 bytes 
    PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x207 bytes 
    PresentationCore.dll!System.Windows.Interop.HwndSource.SetLayoutSize() + 0xbf bytes 
    PresentationCore.dll!System.Windows.Interop.HwndSource.SizeToContent.set(System.Windows.SizeToContent value) + 0x60 bytes 
    PresentationFramework.dll!System.Windows.Window.OnSizeToContentChanged(System.Windows.SizeToContent sizeToContent) + 0x60 bytes 
    PresentationFramework.dll!System.Windows.Window._OnSizeToContentChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) + 0x52 bytes  
    WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x4c bytes 
    PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) + 0x50 bytes 
    WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args) + 0x3c bytes 
    WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex = {System.Windows.EntryIndex}, System.Windows.DependencyProperty dp = {System.Windows.DependencyProperty}, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry = {System.Windows.EffectiveValueEntry}, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType) + 0x723 bytes  
    WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal) + 0x2eb bytes 
    WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) + 0x35 bytes 
    PresentationFramework.dll!System.Windows.Window.SizeToContent.set(System.Windows.SizeToContent value) + 0x4c bytes 
> UCL.exe!UCL.Classes.ViewBase.OnSizeToContentChanged(System.Windows.DependencyObject o = {UCL.Views.EditorView}, System.Windows.DependencyPropertyChangedEventArgs e = {System.Windows.DependencyPropertyChangedEventArgs}) Line 50 + 0x67 bytes C# 

編輯#1:

我看着我的窗口權當SizeToContent設置的屬性。 IsMeasureValid = false,並且IsArrangeValid =真 ,然而從MSDN:

如果IsMeasureValid爲假,IsArrangeValid也必須是假的(由佈局處理的執行邏輯,配置不能沒有測量第一個是有效的有效期)。

我有一個ResizeMode類似的屬性,當這個改變時,似乎設置了IsMeasureValid = false。

我應該注意,我做了這個,所以我可以在我的XAML中添加ResizeMode =「CanResizeWithGrip」SizeToContent =「Manual」。

我做了一些嘗試InvalidateArrange和UpdateLayout,但沒有骰子。 我可以生活在沒有它,但我真的想弄清楚......

+0

Brr中,你不得不懷疑,如果這是真的意味着是生產代碼。故意調用FailFast有點粗俗。 – 2010-10-15 16:26:43

回答

0

看着System.Windows.UIElement.PropagateResumeLayout,斷言失敗,如果一個措施或安排通過已經進行時該方法被調用。

有沒有可能是你的用戶控件試圖設置SizeToContent屬性,當它被調整或在WPF問它任何其他國家進行佈局或安排通?

相關問題