10

簡単なC#Windows8グリッドアプリケーションを作成しました。

このレイアウトに慣れていない場合は、ここに簡単な説明があります:

リンク

私が欲しいのは単純です-いくつかのカスタムItemDetailPagesGroupDetailPageとのいくつかの項目をクリックして、複数の画像を含めることができるGroupedItemsPageカスタムファイルに移動できるようにしたいと思います。.xaml

私が見逃していた簡単な方法があると確信しています。また、この情報は多くの人々に役立つと確信しているので、この質問に報奨金を提供します。

私はこれまでこれを行うのに苦労しました:

私はクラスでを作成しCustomDataItemました:SampleDataSource.cs

 /// <summary>
    /// Generic item data model.
    /// </summary>
    public class CustomDataItem : SampleDataCommon
    {
        public CustomDataItem(String uniqueId, String title, String subtitle, String imagePath, String description, String content, SampleDataGroup group)
            : base(uniqueId, title, subtitle, imagePath, description)
        {
            this._content = content;
            this._group = group;
        }

        private string _content = string.Empty;
        public string Content
        {
            get { return this._content; }
            set { this.SetProperty(ref this._content, value); }
        }

        private SampleDataGroup _group;
        public SampleDataGroup Group
        {
            get { return this._group; }
            set { this.SetProperty(ref this._group, value); }
        }
    }

ただし、明らかに、ObservableCollection

private ObservableCollection<SampleDataGroup> _allGroups = new ObservableCollection<SampleDataGroup>();
public ObservableCollection<SampleDataGroup> AllGroups
{
    get { return this._allGroups; }
}

別のデータ型では不可能です。では、この場合はどうすればよいですか?

どうもありがとう。

4

2 に答える 2

3

はい、カスタムまたは別のデータ型を作成できるはずです。グリッドテンプレートを使用してWin8アプリを作成すると、テンプレートが3つのことを実行することがわかります。1)ベースであるSampleDataCommon、SampleDataCommonを実装し、2つの新しいプロパティ(コンテンツとグループ)を追加するSampleDataItemの3つのタイプを作成します。 、およびSampleDataGroupも実装し、メソッドItemsCollectionChangedを追加し、ItemsとTopItemsの2つのプロパティを追加します。2)SampleDataSourceというクラスを作成します。このクラスでは、SampleDataGroupのコレクションが作成され、AllGroups:ObservableCollectionAllGroupsという名前が付けられます。3)SampleDataSourceのItemsとAllGroupsをXMALページのオブジェクトにバインドします。

あなたの場合、同じデータ構造を使用します。つまり、アイテムなどでグループを作成します。

于 2013-03-16T17:15:23.187 に答える
3

単純なグリッドアプリケーションがあります。グループアイテムページの要素の1つをカスタムアイテム詳細ページにリンクできるようにするにはどうすればよいですか?

では、VisualStudioの「グリッドアプリ」テンプレートを使用したときに生成されるアプリを見てみましょう。

グループアイテムページの要素のデータクラスはSampleDataItemクラスです。できることは、ナビゲーションの処理方法を示すある種のデータフィールド(、、、またはその他)をbool追加することです。intこの例では、シンプルに保っているのでbool、ナビゲーションがカスタムかどうかを示すためにを追加します。

public class SampleDataItem : SampleDataCommon
{
    // add flag as last param
    public SampleDataItem(String uniqueId, String title, String subtitle, 
        String imagePath, String description, String content, SampleDataGroup group, 
        bool isCustomNav = false)
    : base(uniqueId, title, subtitle, imagePath, description)
    {
        this._content = content;
        this._group = group;
        this.IsCustomNav = isCustomNav;
    }

    // to keep it simple this doesn't handle INotifyPropertyChange, 
    // as does the rest of the properties in this class.
    public bool IsCustomNav { get; set; }

    ...
}

したがって、表示する新しいオブジェクトを追加するときは、コンストラクターでフィールドSampleDataItemを設定するだけです。isCustomNav

ここで行う必要があるのは、グループ化されたアイテムページ(GroupedItemsPage.xaml.cs)のグリッドにある既存のクリックイベントハンドラーを変更することだけです。

void ItemView_ItemClick(object sender, ItemClickEventArgs e)
{
    // Navigate to the appropriate destination page, configuring the new page
    // by passing required information as a navigation parameter
    var item = (SampleDataItem)e.ClickedItem;
    var itemId = item.UniqueId;

    if (item.IsCustomNav == false)
    {
        // default
        this.Frame.Navigate(typeof(ItemDetailPage), itemId);
    }
    else
    {
        // custom page
        this.Frame.Navigate(typeof(ItemDetailPage2), itemId);
    }
}

上記で行っているのは、選択したアイテムを取得してから、前に追加したナビゲーションフラグをテストすることだけです。これに基づいて、元のItemDetailPageまたは新しいものに移動しますItemDetailPage2。前に述べたように、ナビゲーションフラグはである必要はありませんboolintナビゲートする場所を示す、またはenumまたはその他のタイプにすることができます。

GroupDetailsPageで同様の動作が必要な場合は、同じ方法でクリックイベントハンドラーを更新する必要があることに注意してください。

お役に立てば幸いです。

于 2013-03-19T06:56:59.403 に答える