I am developing a metro application for Windows 8. I am using the GridApp (xaml) project, but I want to use different group styles in each section.
My code is:
public class GroupTemplateSelector : GroupStyleSelector
{
public GroupStyle NewsItemGroupStyle { get; set; }
public GroupStyle NormalGroupStyle { get; set; }
protected override GroupStyle SelectGroupStyleCore(object group, uint level)
{
if (level == 3)
{
return NewsItemGroupStyle;
}
else
{
return NormalGroupStyle;
}
throw new ArgumentException("Unexpected group type");
}
}
I use this class to style group selectors and XAML
<GroupStyle x:Key="NewsItemGroupStyle">
<GroupStyle.HeaderTemplate>
<DataTemplate>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" Margin="0,0,80,0" VerticalAlignment="Bottom"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
<GroupStyle x:Key="NormalGroupStyle">
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="1,0,0,6">
<Button
AutomationProperties.Name="Group Title"
Content="{Binding Title}"
Background="Blue"
Click="Header_Click"
Style="{StaticResource TextButtonStyle}"
/>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
<common:GroupTemplateSelector
x:Key="groupSelector"
NewsItemGroupStyle="{StaticResource NewsItemGroupStyle}"
NormalGroupStyle="{StaticResource NormalGroupStyle}" />
but the style group changes immediately.
source
share