我正在写一个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:
<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如果我没有获得任何信息。 有没有一种方法,我可以通过沿着这些线路的附加属性或东西传递的属性?