How to insert an image list in the grouped items page befor each group?

前端 未结 1 472
广开言路
广开言路 2021-01-23 05:44

I am currently developing a windows 8 application using XAML and C#. I developed the grouped items page that generates data groups dynamically. I have a list of social media ico

相关标签:
1条回答
  • 2021-01-23 06:00

    Define GroupItemStyle in page resources section as follows:

    <Style x:Key="GroupItemStyle1" TargetType="GroupItem">
                <Setter Property="IsTabStop" Value="False"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="GroupItem">
                            <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="431*"/>
                                        <ColumnDefinition Width="429*"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>
                                    <ContentControl x:Name="HeaderContent" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" Content="{TemplateBinding Content}" IsTabStop="False" Margin="{TemplateBinding Padding}" TabIndex="0" Grid.Column="1"/>
                                    <ItemsControl x:Name="ItemsControl" IsTabStop="False" ItemsSource="{Binding GroupItems}" Grid.Row="1" TabIndex="1" TabNavigation="Once" Grid.Column="1">
                                        <ItemsControl.ItemContainerTransitions>
                                            <TransitionCollection>
                                                <AddDeleteThemeTransition/>
                                                <ContentThemeTransition/>
                                                <ReorderThemeTransition/>
                                                <EntranceThemeTransition IsStaggeringEnabled="False"/>
                                            </TransitionCollection>
                                        </ItemsControl.ItemContainerTransitions>
                                    </ItemsControl>
                                    <!-- ***** Put your social icon list here **** Start-->
                                    <Button Content="Button" HorizontalAlignment="Left" Margin="0,194,0,0" Grid.Row="1" VerticalAlignment="Top"/>
                                    <!-- ***** Put your social icon list here **** End -->
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    

    Apply this style to GridView as:

    <!-- Horizontal scrolling grid used in most view states -->
            <GridView
                x:Name="itemGridView"
                AutomationProperties.AutomationId="ItemGridView"
                AutomationProperties.Name="Grouped Items"
                Grid.RowSpan="2"
                Padding="116,137,40,46"
                ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
                ItemTemplate="{StaticResource Standard250x250ItemTemplate}"
                SelectionMode="None"
                IsSwipeEnabled="false"
                IsItemClickEnabled="True"
                ItemClick="ItemView_ItemClick">
    
                <GridView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </GridView.ItemsPanel>
                <GridView.GroupStyle>
                    <GroupStyle ContainerStyle="{StaticResource GroupItemStyle1}">
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <Grid Margin="1,0,0,6">
                                .......
                      </GroupStyle>
            </GridView.GroupStyle>
        </GridView>
    

    You will see the sample button before each group here - enter image description here

    UPDATE:

    Use following group styles: for example:

      <Style x:Key="GroupItemStyle3" TargetType="GroupItem">
            <Setter Property="IsTabStop" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="GroupItem">
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="431*"/>
                                    <ColumnDefinition Width="429*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <ContentControl x:Name="HeaderContent" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" Content="{TemplateBinding Content}" IsTabStop="False" Margin="{TemplateBinding Padding}" TabIndex="0" Grid.ColumnSpan="2"/>
                                <ItemsControl x:Name="ItemsControl" IsTabStop="False" ItemsSource="{Binding GroupItems}" Grid.Row="1" TabIndex="1" TabNavigation="Once" Grid.Column="1">
                                    <ItemsControl.ItemContainerTransitions>
                                        <TransitionCollection>
                                            <AddDeleteThemeTransition/>
                                            <ContentThemeTransition/>
                                            <ReorderThemeTransition/>
                                            <EntranceThemeTransition IsStaggeringEnabled="False"/>
                                        </TransitionCollection>
                                    </ItemsControl.ItemContainerTransitions>
                                </ItemsControl>
    
    
                                <StackPanel Background="Red" Grid.Row="1">
            <!-- ***** Put your social icon list here **** Start-->                 
                <Button Content="Button" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top"/>
                                <!-- ***** Put your social icon list here **** End -->
                                </StackPanel>
    
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    

    this will give you:

    enter image description here

    And this one will:

     <Style x:Key="GroupItemStyle2" TargetType="GroupItem">
                <Setter Property="IsTabStop" Value="False"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="GroupItem">
                            <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="431*"/>
                                        <ColumnDefinition Width="429*"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>
                                    <ContentControl x:Name="HeaderContent" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" Content="{TemplateBinding Content}" IsTabStop="False" Margin="{TemplateBinding Padding}" TabIndex="0" Grid.Column="1"/>
                                    <ItemsControl x:Name="ItemsControl" IsTabStop="False" ItemsSource="{Binding GroupItems}" Grid.Row="1" TabIndex="1" TabNavigation="Once" Grid.Column="1">
                                        <ItemsControl.ItemContainerTransitions>
                                            <TransitionCollection>
                                                <AddDeleteThemeTransition/>
                                                <ContentThemeTransition/>
                                                <ReorderThemeTransition/>
                                                <EntranceThemeTransition IsStaggeringEnabled="False"/>
                                            </TransitionCollection>
                                        </ItemsControl.ItemContainerTransitions>
                                    </ItemsControl>
    
    
                                    <StackPanel  Grid.RowSpan="2" Background="Red">
                                        <!-- ***** Put your social icon list here **** Start-->
                                        <Button Content="Button" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top"/>
                                        <!-- ***** Put your social icon list here **** End -->
                                    </StackPanel>
    
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    

    enter image description here

    0 讨论(0)
提交回复
热议问题