如何在Metro GridView中使用不同的布局?

我正在写一个Windows 8 Metro应用程序。 我正在尝试使用三个组绘制GridView。 我希望其中一个组以不同于其他组的方式布置项目。 我之前在WPF中使用过选择器,所以我认为这是一条很好的路线。 所以我尝试了GroupStyleSelector,我在MSDN上找到了这个例子 :

public class ListGroupStyleSelector : GroupStyleSelector { protected override GroupStyle SelectGroupStyleCore(object group, uint level) { return (GroupStyle)App.Current.Resources["listViewGroupStyle"]; } } 

所以我改编/扩展了适合我的东西:

CS:

 public class ExampleListGroupStyleSelector : GroupStyleSelector { public ExampleListGroupStyleSelector () { OneBigItemGroupStyle = null; NormalGroupStyle = null; } public GroupStyle OneBigItemGroupStyle { get; set; } public GroupStyle NormalGroupStyle { get; set; } protected override GroupStyle SelectGroupStyleCore( object group, uint level ) { // a method that tries to grab an enum off the bound data object var exampleListType= GetExampleListType( group ); if ( exampleListType== ExampleListType.A) { return OneBigItemGroupStyle; } if ( exampleListType== ExampleListType.B|| exampleListType== ExampleListType.B) { return NormalGroupStyle; } throw new ArgumentException( "Unexpected group type" ); } } 

XAML:

           

但是我在选择器中给出的组是null或者DependencyObject,我似乎无法获得任何数据。 如果我没有得到任何信息,我怎么能做出如何更改GroupStyle的明智决定。 有没有办法可以通过附属物或其他东西传递财产?

基于此论坛主题,您可以通过将对象强制转换为ICollectionView并访问.Group属性来提取对象,您将获得绑定该组的对象。 这允许对模板进行智能决策。 但是它仍然不适用于我(或线程中的其他人),因为尽管返回了不同的样式,但只应用了一种样式。

编辑:事实certificate,GroupTemplate并不打算生成不同的组。 它旨在更改组的视图,例如在快照视图或所有组更改的类似情况下。