数据绑定0x8000ffff上的wp7奇怪的UnhandledException

wp7*_*dev 6 data-binding windows-phone-7

我在数据绑定期间遇到一个奇怪的未处理异常.我将ListBox与IList数据绑定.在使用对象填充列表后,我将ListBox的DataContext设置为我的对象:

IList<Users> users = new List<Users>;
foreach(JToken jresult in Users)
{
User juser = JsonConvert.DeserializeObject<User>(jresult.ToString());
users.Add(juser);

this.DataContext = myObject;
Run Code Online (Sandbox Code Playgroud)

我的对象只有两个字段,名称和电子邮件:

public class User
{
    public string name { get; set; }
    public string email { get; set; }    }
Run Code Online (Sandbox Code Playgroud)

在XAML方面,我绑定ListItem和ItemTemplate中的文本块,如下所示:

<ListBox Name="Users" ItemsSource="{Binding}">
<TextBlock Text="{Binding Name}" Name="name" />
<TextBlock Text="{Binding Email}" Name="email" />
Run Code Online (Sandbox Code Playgroud)

在调试过程中,我可以看到用户列表框中填充了正确的项目,但是在退出方法后,应用程序崩溃了,我直接进入App.xaml.cs方法Application_UnhandledException.错误详细信息如下:

e.ExceptionObject.InnerException
{"0x8000ffff"}
    _data: null
    _HResult: -2146233088
    _innerException: null
    _message: "0x8000ffff"
    _methodDescs: {System.IntPtr[14]}
    _optionalData: null
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233088
    InnerException: Could not evaluate expression
    Message: "0x8000ffff"
    StackTrace: "   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)\r\n   at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)\r\n   at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)\r\n   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)\r\n   at MS.Internal.XcpImports.MeasureNative(IntPtr element, Single inWidth, Single inHeight)\r\n   at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)\r\n   at System.Windows.UIElement.Measure(Size availableSize)\r\n   at System.Windows.Controls.VirtualizingStackPanel.MeasureChild(UIElement child, Size layoutSlotSize)\r\n   at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)\r\n   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)\r\n   at MS.Internal.XcpImpor
ts.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)\r\n   at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)\r\n   at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)\r\n   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)\r\n"
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚这一点,并且非常感谢任何指导,或者对这类问题采取更好的方法.有一篇文章确实提到SilverLight不再支持ListDictionaryInternal,所以我不确定这是否可能是问题,因为错误详细信息指向ListDictionaryInternal.

fir*_*lys 3

想听听一些奇怪的事情。我遇到了这个问题,并在 XAML 中删除了 style="{StaticResource ....} 并修复了它。有人可以解释为什么吗?之后我添加了一个本地 StaticResource,它也起作用了。

如果您的列表框项目中的任何位置都没有设置样式,那么此解决方案将无济于事。