我的应用程序更新到 10 时出现问题。它在 Windows 8/8.1 中工作,尽管我认为我可能已经得到它,但 Windows 8 它没有崩溃。基本上我有我从网上提取的数据,当我查看它时,这一切似乎都是正确的。唯一的事情是我有一个可观察的集合,我在其中定义了参数/变量(并且由于我对应用程序中的两个不同部分使用相同的网格视图,有时我将某些字段设置为空,因为它们没有被使用。)
这是我的基类
public class sTumblrblog_gv : INotifyPropertyChanged
{
private string title;
public string Title
{
get
{
return title;
}
set
{
title = value;
NotifyPropertyChanged();
}
}
private string url;
public string Url
{
get
{
return url;
}
set
{
url = value;
NotifyPropertyChanged();
}
}
private string avatarimage;
public string AvatarImage
{
get
{
return avatarimage;
}
set
{
avatarimage = value;
NotifyPropertyChanged();
}
}
private string blogposts;
public string BlogPosts
{
get
{
return blogposts;
}
set
{
blogposts = value;
NotifyPropertyChanged();
}
}
private bool isnsfw;
public bool IsNsfw
{
get
{
return isnsfw;
}
set
{
isnsfw = value;
NotifyPropertyChanged();
}
}
private BitmapImage dlimage;
public BitmapImage DLImage
{
get
{
return dlimage;
}
set
{
dlimage = value;
NotifyPropertyChanged();
}
}
public string ImgName { get; set; }
public sTumblrblog_gv()
{
//string Title;
//string Url;
//string AvatarImage;
//string BlogPosts;
//bool IsNsfw;
}
public sTumblrblog_gv(IRandomAccessStream stream, string imgname)
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(stream);
DLImage = bmp;
ImgName = imgname;
}
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
我用它来创建集合:
ObservableCollection<sTumblrblog_gv> sTumblrblog_gv_list = newObservableCollection<sTumblrblog_gv>();
这是我的gridview数据模板:
<DataTemplate x:Key="imageTemplate">
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal">
<StackPanel Orientation="Horizontal">
<!-- <WrapGrid Orientation="Horizontal"/>-->
<Border Height="100" Width="100" >
<Image Source="{Binding AvatarImage}" Stretch="UniformToFill" ImageFailed="Photo_ImageFailed" />
</Border>
<StackPanel Orientation="Vertical" VerticalAlignment="Top" Margin="10">
<Image Source="{Binding DLImage}" MaxHeight="100" ImageFailed="Photo_ImageFailed" />
<TextBlock Margin="10,0,0,0" Text="{Binding Title}" FontSize="12" />
<TextBlock Margin="10,2,0,0" Text="{Binding Url}" FontSize="12" />
<TextBlock Margin="10,2,0,0" Text="{Binding BlogPosts}" FontSize="12" />
<CheckBox IsChecked="{Binding IsNsfw}" x:Uid="Nsfw" />
<!-- <Image Source="{Binding Path=Thumbnail,Converter={StaticResource imageConverter}}" MaxHeight="100" />-->
</StackPanel>
</StackPanel>
</ItemsWrapGrid>
</ItemsPanelTemplate>
</DataTemplate>
<CollectionViewSource x:Name="sTumblrCVS"/>
当我逐步浏览这些部分时,我到达了我实际将元素添加到 gridview 的部分,这就是它崩溃的地方。我尝试使用调度程序来避免任何 UI 线程与后台线程类型问题。
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
sTumblrblog_gv_list.Add(new sTumblrblog_gv() { Title = tumblrusrfollow.Title, Url = tumblrusrfollow.Url.ToString(), AvatarImage = imageavatar.ToString(), BlogPosts = blogposts, IsNsfw = blogisnfw, DLImage = null, ImgName = "" });
});
它在我添加“参数不正确”的异常作为 {Windows.UI.Xaml.UnhandledExceptionEventArgs} 后立即崩溃 -
本机视图 0x0ea7ea20 {...} IUnknown * {Windows.UI.Xaml.dll!ctl::ComObject}
[0] 0x52b58210 {Windows.UI.Xaml.dll!ctl::ComObject::QueryInterface(const _GUID &, void * *)} 空白 *
在玩了几天之后,这让我相信我作为源发送的数据有些东西。
但是我什至在将其发送到 Observable 集合之前枚举的数据与应该的类型和字段匹配。(根据视觉工作室,我没有任何错误,匹配类型等。)
使用gridview的8到10之间有什么变化吗?