2012-07-10 4 views
12

私はWindows 8 Metroアプリケーションを作成しています。私は3つのグループでGridViewを描画しようとしています。私はそれらのグループの1つに、他のグループとは異なるアイテムをレイアウトしてほしい。以前WPFでSelectorsを使用していたので、それは良いルートだと思っていました。だから私はGroupStyleSelectorを試してみましたが、私はこのexample on MSDNが見つかりました:メトロGridViewのグループを異なるレイアウトで使用するにはどうすればいいですか?

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:

<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> 

セレクタで与えられたグループはnullまたはDependencyObject thaです私はデータを消しているようには見えません。もし私が何の情報も与えられていなければGroupStyleの変更方法について賢明な決断を下すべきですか?添付されたプロパティやその行に沿って何かを渡すことができる方法はありますか?

答えて

1

このフォーラムthreadに基づいて、オブジェクトをICollectionViewにキャストし、グループにバインドしたオブジェクトを取得する.Groupプロパティにアクセスすることでオブジェクトを抽出できます。これにより、テンプレートのインテリジェントな決定が可能になります。しかし、異なるスタイルが返されるにもかかわらず、1つのスタイルだけが適用されるため、私(またはスレッドの他の人)のためにはまだ機能しません。

編集:GroupTemplateは異なるグループを作成するためのものではないことが判明しました。たとえば、スナップされたビューまたはすべてのグループが変更される類似のケースで、グループのビューを変更することを意図しています。

関連する問題