私は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の変更方法について賢明な決断を下すべきですか?添付されたプロパティやその行に沿って何かを渡すことができる方法はありますか?