1

アプリを 10 用に更新する際に問題が発生しています。Windows 8/8.1 でも動作しましたが、Windows 8 ではクラッシュしませんでした。基本的に、オンラインから取得したデータがあり、それを見ると、すべて正しいように見えます。唯一のことは、パラメーター/変数を定義した監視可能なコレクションがあることです (アプリの 2 つの異なる部分に同じグリッドビューを使用しているため、使用されていないために特定のフィールドが null になることがあります)。

これが私の基本クラスです

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>();

グリッドビューのデータ テンプレートは次のとおりです。

    <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"/>

パーツをステップ実行すると、実際にグリッドビューに要素を追加するセクションに到達し、そこでクラッシュします。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 の間で何か変更がありましたか?

4

0 に答える 0