c# – Windows 8网格应用程序中的自定义详细页面

前端之家收集整理的这篇文章主要介绍了c# – Windows 8网格应用程序中的自定义详细页面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个简单的C# Windows 8网格应用程序.

如果你不熟悉这个布局,这里有一个简短的解释:

Link

我想要的是简单的 – 一些自定义ItemDetailPages.我想要点击GroupDetailPage和GroupedItemsPage上的某些项目,并导航到一个自定义的.xaml文件,其中可以包含多个图像.

我相信有一个简单的做法,我已经错过了,我也确信这些信息对许多人来说是有用的,所以我会提供一个这个问题的赏金.

到目前为止,我一直在努力工作:

我在SampleDataSource.cs类中创建了一个CustomDataItem:

/// <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; }
}

不可能使用不同的数据类型.那么在这种情况下我该怎么办?

非常感谢.

解决方法

I have a simple grid application; how do I make it possible to have one of the elements in the group item page link to a custom item detail page ?

好的,让我们从Visual Studio中使用“Grid App”模板时生成的应用程序.

组项目页面上的元素的数据类是SampleDataItem类.您可以做的是添加一些类型的数据字段(bool,int或其他),指示如何处理导航.在这个例子中,我们保持简单,所以我们添加一个bool来指示导航是否是自定义的.

public class SampleDataItem : SampleDataCommon
{
    // add flag as last param
    public SampleDataItem(String uniqueId,SampleDataGroup group,bool isCustomNav = false)
    : base(uniqueId,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)上更改已经存在的网格中的click事件处理程序:

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的新的.如前所述,导航标志不一定是一个bool.它可以是一个int或枚举或其他类型,告诉我们在哪里导航.

请注意,如果您想要在GroupDetailsPage类似的行为,您只需要以相同的方式更新点击事件处理程序.

希望有帮助.

原文链接:https://www.f2er.com/csharp/94613.html

猜你在找的C#相关文章