我已经在我的视图基类中添加了一个依赖项属性,它应该允许子UserControls在父窗口上设置一些属性,一个是SizeToContent。当我的OnSizeToContent方法运行时,当它试图将主窗口的SizeToContent从WidthAndHeight更改为Manual时,我得到了这个奇怪的错误:
检测到FatalExecutionEngineError 消息:运行时遇到致命错误。在线程0x17e8上,错误的地址为0x58e29ddd。错误代码是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 = true ,但是来自msdn:
如果IsMeasureValid为false,则IsArrangeValid也必须为false(通过布局过程的强制逻辑,如果没有测量首先有效,则排列无效)。
我有一个ResizeMode的类似属性,当它发生变化时,似乎设置了IsMeasureValid = false。
我应该注意,我这样做了,所以我可以将ResizeMode =“CanResizeWithGrip”SizeToContent =“Manual”添加到我的XAML。
我做了一些InvalidateArrange和UpdateLayout的实验,但没有骰子。 我可以没有它,但我真的很想弄明白......
答案 0 :(得分:0)
查看System.Windows.UIElement.PropagateResumeLayout,如果在调用方法时测量或排列传递正在进行中,则断言失败。
您的UserControl是否有可能在调整大小时设置SizeToContent属性或WPF要求它执行布局或安排传递的任何其他状态?