上下文是Windows Phone 7的Silverlight应用程序。我正在使用模拟器进行调试。
我有一个MainPage.xaml
,其DataContext附加了一个ViewModel
当页面为NavigatedTo
时,会在ViewModel中调用一个方法来调用API并显示信息。
我有一个创建Dictionary<string, string>
的方法,用数据填充它并将其设置在实现PropertyChanged
事件的属性中。
调用此方法后,调试器在App.Application_UnhandledException中以NotImplementedException中断。
如果我使用调试器跳过对此方法的调用,则不会引发异常。
奇怪的是,在调用方法之后引发了异常,而不是在内部!该异常不包含InnerException。有一个-2147467263的HResult和一个包含“0x80004001”的消息。这是StackTrace:
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureNative(IntPtr element, Single inWidth, Single inHeight)
at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at Microsoft.Phone.Controls.Primitives.PanoramaPanel.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at Microsoft.Phone.Controls.Panorama.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at Microsoft.Phone.Controls.PhoneApplicationFrame.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
调试输出包含:
A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll (x10)
A first chance exception of type 'System.NotImplementedException' occurred in System.Windows.dll (x6)
答案 0 :(得分:1)
OHW。我通过检查XAML端的数据绑定找到了用户错误。这是我的XAML:
<TextBlock Grid.Column="0" Text="{Binding Value}"
Style="PhoneTextLargeStyle" />
<TextBlock Grid.Column="1" Text="{Binding Key}"
Style="PhoneTextLargeStyle" />
我忘了把它写成静态资源:
<TextBlock Grid.Column="0" Text="{Binding Value}"
Style="{StaticResource PhoneTextLargeStyle}" />
<TextBlock Grid.Column="1" Text="{Binding Key}"
Style="{StaticResource PhoneTextLargeStyle}" />
让我们希望这个愚蠢的问题/自动回答会帮助某人:)