How to prevent ListView inside TabViewItem from overflowing the screen

Apptacular Apps 386 Reputation points
2020-06-06T20:26:00.873+00:00

How

<controls:TabView
    Grid.Row="1"
    x:Name="Tabs"
    TabWidthBehavior="Actual"
    CanCloseTabs="False"
    IsCloseButtonOverlay="False"
    CanDragItems="False"
    CanReorderItems="False"
    AllowDrop="False"
    SelectedTabWidth="200">

    <!-- Tabs -->
    <controls:TabViewItem>
        <ListView
          x:Name="List"
          Padding="16"
          IsItemClickEnabled="True"
          ItemsSource="{x:Bind listItem}">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Title}" 
                    Style="{StaticResource TitleTextBlockStyle}" />
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </controls:TabViewItem>
    <controls:TabViewItem>
        <TextBlock Padding="16">You can enable drag-and-drop and reorder the tabs too.</TextBlock>
    </controls:TabViewItem>
</controls:TabView>
Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Matt Lacey 791 Reputation points MVP
    2020-06-06T21:25:25.613+00:00

    Put a Grid inside the TabViewItem and then put the ListView inside the Grid.

    The Grid will be limited to the visible space on the screen (unless you size it otherwise) and so won't expand indefinitely like the TabViewItem. It will also constrain the ListView to stop that growing to fit all its children/items.

    0 comments No comments

0 additional answers

Sort by: Most helpful