Ich schreibe eine Windows 8 Metro App. Ich versuche ein GridView mit drei Gruppen zu zeichnen. Ich möchte, dass eine dieser Gruppen ihre Artikel anders gestaltet als die anderen. Ich habe früher in WPF Selektoren verwendet, also dachte ich mir, das wäre ein guter Weg. Also habe ich versucht, die Group und ich fand diese example on MSDN:Wie kann ich Gruppen in einem Metro GridView verschiedene Layouts verwenden?
public class ListGroupStyleSelector : GroupStyleSelector
{
protected override GroupStyle SelectGroupStyleCore(object group, uint level)
{
return (GroupStyle)App.Current.Resources["listViewGroupStyle"];
}
}
So verändert I/erweitert auf sie von etwas, das mir passen würde:
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>
Aber die Gruppe, die ich im Selektor angegeben habe, ist null oder ein DependencyObject tha t Ich kann anscheinend keine Daten abrufen. Wie soll ich eine intelligente Entscheidung treffen, wie ich den GroupStyle ändern kann, wenn ich keine Informationen bekomme? Gibt es eine Möglichkeit, dass ich eine Immobilie durch eine angefügte Immobilie oder etwas in dieser Richtung weitergeben kann?