Group style selection in gridview

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)
    {
        // a method that tries to grab an enum off the bound data object

        if (level == 3)
        {
            return NewsItemGroupStyle;
        }
        else
        {
            return NormalGroupStyle;
        }

        throw new ArgumentException("Unexpected group type"); 

    }
}

I use this class to style group selectors and XAML

<!-- NewsItemGroupStyle -->
<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>


<!-- NormalItemGroupStyle -->
<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>

<!-- selector -->
<common:GroupTemplateSelector 
    x:Key="groupSelector"
    NewsItemGroupStyle="{StaticResource NewsItemGroupStyle}"
    NormalGroupStyle="{StaticResource NormalGroupStyle}" />

but the style group changes immediately.

+5
source share
1 answer

Lvsti, GroupStyleSelector . 0 , 1 . 0 . , , , , . , .

Dev, : http://bit.ly/winappsupport

0

All Articles