我在写一个Windows 8 Metro应用程序。我试图绘制一个带有三个组的GridView。我希望这些团队中的一个以不同于其他人的方式布置他们的物品。我之前在WPF中使用过选择器,所以我认为这将是一条很好的路线。所以我尝试了GroupStyleSelector我发现这个example on MSDN:如何让Metro 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的明智决定。有没有一种方法可以通过附属资产或其他方式传递资产?