Vertical scrolling inside GridView group of items in WinRT XAML

后端 未结 4 1006
花落未央
花落未央 2021-01-12 13:18

I am using GridView for displaying groups of different sets of items in a WinRT XAML app. Everything works well, except that the ItemsPanelTemplate uses a wrapping grid whic

相关标签:
4条回答
  • 2021-01-12 13:52

    I would place your elements inside a scroll viewer directly. Like this:

    <GroupStyle.Panel>
     <ItemsPanelTemplate>
          <ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollMode="Disabled" ZoomMode="Disabled" VerticalScrollMode="Enabled">
                <StackPanel Orientation="Vertical" Visibility="Visible" />
          </ScrollViewer>
     </ItemsPanelTemplate>
    

    I hope this helps, Lance

    0 讨论(0)
  • 2021-01-12 13:57

    What about this?

    It renders elements like this:
    Item 1 Item 2
    Item 3 Item 4

    <ListView Width="200">
        <ListBoxItem>
            <TextBlock>Item 1</TextBlock>
        </ListBoxItem>
        <ListBoxItem>
            <TextBlock>Item 2</TextBlock>
        </ListBoxItem>
        <ListBoxItem>
            <TextBlock>Item 3</TextBlock>
        </ListBoxItem>
        <ListBoxItem>
            <TextBlock>Item 4</TextBlock>
        </ListBoxItem>
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapGrid Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
    </ListView>
    
    0 讨论(0)
  • 2021-01-12 14:03

    You may also wants to set the ZoomMode of the ScrollViewer to Disabled :)

    Regards

    0 讨论(0)
  • 2021-01-12 14:04

    OK, I finally solved it! To whom it may concern:

    <GroupStyle.ContainerStyle>
        <Style TargetType="GroupItem">
            <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="GroupItem">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <ContentPresenter Content="{TemplateBinding Content}" Grid.Row="0"/>
                        <ItemsControl x:Name="ItemsControl2" ItemsSource="{Binding GroupItems}" Grid.Row="1">
                            <ItemsControl.Template>
                            <ControlTemplate>
                                <ScrollViewer x:Name="ScrollViewer" VerticalScrollBarVisibility="Hidden"                                                  VerticalScrollMode="Enabled" HorizontalScrollBarVisibility="Disabled"                                                  HorizontalScrollMode="Disabled">
                                <ItemsPresenter />
                                </ScrollViewer>
                            </ControlTemplate>
                            </ItemsControl.Template>
                        </ItemsControl>
                    </Grid>
               </ControlTemplate>
           </Setter.Value>
           </Setter>
       </Style>
    </GroupStyle.ContainerStyle>
    

    It's important that you use the Grid to make sure that the ScrollViewer scales correctly.

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