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; } } 不可能使用不同的数据类型.那么在这种情况下我该怎么办? 非常感谢. 解决方法
好的,让我们从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类似的行为,您只需要以相同的方式更新点击事件处理程序. 希望有帮助. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |