Установка SizeToContent для дочернего UserControl вызывает FatalExecutionEngineError - PullRequest
0 голосов
/ 15 октября 2010

Я добавил свойство зависимости в свой базовый класс представления, которое должно позволять дочерним элементам UserControls устанавливать некоторые свойства в родительском окне, одним из которых является SizeToContent.Когда мой метод OnSizeToContent запускается, когда он пытается изменить параметр SizeToContent главного окна с WidthAndHeight на Manual, я получаю эту странную ошибку:

Обнаружена ошибка FatalExecutionEngineError. Сообщение: во время выполнения обнаружена фатальная ошибка.Адрес ошибки был 0x58e29ddd, в потоке 0x17e8.Код ошибки 0x80131623.Эта ошибка может быть ошибкой в ​​CLR или в небезопасных или не поддающихся проверке частях пользовательского кода.Распространенные источники этой ошибки включают в себя ошибки пользовательского маршалинга для COM-взаимодействия или 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:

I 'я смотрю на свойства моего окна прямо при установке SizeToContent.IsMeasureValid = false и IsArrangeValid = true, но из msdn:

Если IsMeasureValid имеет значение false, IsArrangeValid также должно быть false (из-за принудительной логики процесса компоновки компоновка не может быть действительной без измерения, вначале действительного).

У меня есть похожее свойство для ResizeMode, и когда это меняется, кажется, устанавливается IsMeasureValid = false.

Следует отметить, что я сделал это, чтобы добавить ResizeMode = "CanResizeWithGrip"SizeToContent =" Вручную "для моего XAML.

Я провел некоторые эксперименты с InvalidateArrange и UpdateLayout, но без кубиков.Я могу жить без этого, но я бы очень хотел понять это ...

1 Ответ

0 голосов
/ 15 октября 2010

Глядя на System.Windows.UIElement.PropagateResumeLayout, завершение завершается неудачно, если при вызове метода уже выполняется проход меры или аранжировки.

Возможно, что ваш UserControl пытается установить SizeToContentсвойство во время его изменения или любое другое состояние, в котором WPF попросил его выполнить макет или организовать передачу?

...