Piszę aplikację Windows 8 Metro. Próbuję narysować GridView z trzema grupami. Chcę, aby jedna z tych grup inaczej układała swoje przedmioty niż pozostałe. Użyłem wcześniej Selectorów w WPF, więc pomyślałem, że to dobra trasa. Więc próbowałem GroupStyleSelector i znalazłem to example on MSDN:Jak utworzyć grupy w GridView Metro używać różnych układów?
public class ListGroupStyleSelector : GroupStyleSelector
{
protected override GroupStyle SelectGroupStyleCore(object group, uint level)
{
return (GroupStyle)App.Current.Resources["listViewGroupStyle"];
}
}
więc zmienione/rozszerzone na niego z czymś, co by pasowało do mnie:
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>
Ale grupa, która jest podana w selektorze ma wartość zerową lub DependencyObject tha t Nie mogę uzyskać żadnych danych. Jak mam podjąć inteligentną decyzję, jak zmienić GroupStyle, jeśli nie dostaję żadnych informacji. Czy istnieje sposób, w jaki mogę przekazać nieruchomość przez dołączoną nieruchomość lub coś podobnego?