我怎样才能使地铁GridView控件组使用不同的布局? [英] How can I make Groups in a Metro GridView use different Layouts?

查看:215
本文介绍了我怎样才能使地铁GridView控件组使用不同的布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Windows 8地铁应用程序。我想画一个GridView三组。我想其中一个组以不同的布局自己的项目比别人。我在WPF之前使用选择器,所以我想这会是一个很好的途径。所以我尝试了GroupStyleSelector,我发现在MSDN上这例如:

I'm writing a Windows 8 Metro app. I'm trying to draw a GridView with three Groups. I want one of those groups to layout their items differently than the others. I've used Selectors before in WPF, so I thought that'd be a good route. So I tried the GroupStyleSelector and I found this example on MSDN :

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



所以我改变/从东西它扩大了会适合我:

So I altered/expanded on it from something that would suit me:

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:

XAML:

<Page.Resources>
  <ExampleListGroupStyleSelector 
     x:Key="ExampleListGroupStyleSelector"
     OneBigItemGroupStyle="{StaticResource OneBigGroupStyle}"
     NormalGroupStyle="{StaticResource NormalGroupStyle}" />
</Page.Resources>
<GridView
     ItemsSource="{Binding Source={StaticResource exampleListsViewSource}}"
     GroupStyleSelector="{StaticResource ExampleListGroupStyleSelector}">
     <GridView.ItemsPanel>
        <ItemsPanelTemplate>
           <VirtualizingStackPanel
              Orientation="Horizontal" />
        </ItemsPanelTemplate>
     </GridView.ItemsPanel>
</GridView>



不过,我在选择我指定的组为空或为DependencyObject,我不能似乎得到任何数据了。我应该如何做出明智的决定如何改变GroupStyle如果我没有获得任何信息。有没有一种方法可以让我通过沿着这些线路附加属性或东西传递的属性?

But the group that I'm given in the selector is null or a DependencyObject that I can't seem to get any data off. How am I supposed to make an intelligent decision as to how to change the GroupStyle if I'm not given any information. Is there a way I can pass a property through an attached property or something along those lines?

推荐答案

根据这个论坛<一个HREF =http://social.msdn.microsoft.com/Forums/hr/winappswithcsharp/thread/5f12273f-e000-4c96-a4bc-6ccc18a104a0?prof=required相对=nofollow>线程可以通过它铸造的ICollectionView和访问。集团财产,你会得到你绑定的组到对象中提取的对象。这使得在模板上明智的决定。但是它仍然不适合我(或其他人在线程),因为尽管不同风格返回的事实只有一个样式应用于工作

Based on this forum thread you can extract the object by casting it to ICollectionView and accessing the .Group property where you will get the object you bound the group to. This allows for intelligent decision on the template. However it still does not work for me (or the other people in the thread) since only one style is applied despite the fact that different styles are returned.

编辑:原来,GroupTemplate不旨在产生不同的组。它的目的是改变组例如在抢购视图或在所有群体改变类似案件的看法。

It turns out the GroupTemplate is not intended to produce different groups. It is intended to change the view of the group for example in snapped view or similar cases where all groups change.

这篇关于我怎样才能使地铁GridView控件组使用不同的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆