ListView dosent scroll

asked 2022-06-28T00:10:53.05+00:00
Eduardo Gomez 2,326 Reputation points

![215496-image.png]1

this is the UI

    <behaviours:Interaction.Triggers>  
        <behaviours:EventTrigger EventName="MouseLeftButtonDown">  
            <behaviours:InvokeCommandAction Command="{Binding DragWindowCommand}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}}" />  
        </behaviours:EventTrigger>  
    </behaviours:Interaction.Triggers>  


    <Window.DataContext>  
        <vm:PrpertiesWindowViewModel />  
    </Window.DataContext>  

    <Window.Resources>  
        <helpers:HasText x:Key="hasText" />  
    </Window.Resources>  

    <Border Style="{StaticResource BrderStyle}">  

        <Grid>  
            <Grid.ColumnDefinitions>  
                <ColumnDefinition Width="1.2*" />  
                <ColumnDefinition Width="*" />  
            </Grid.ColumnDefinitions>  

            <StackPanel>  

                <TextBox  
                    x:Name="NameTxt"  
                    VerticalContentAlignment="Center"  
                    materialDesign:HintAssist.Hint="Name of the property"  
                    materialDesign:HintAssist.IsFloating="True"  
                    Text="{Binding Building.Name}">  

                    <behaviours:Interaction.Triggers>  
                        <behaviours:EventTrigger EventName="PreviewTextInput">  
                            <behaviours:InvokeCommandAction Command="{Binding ValidateTextCommand}" PassEventArgsToCommand="True" />  
                        </behaviours:EventTrigger>  
                    </behaviours:Interaction.Triggers>  
                </TextBox>  

                <TextBox  
                    x:Name="SqTx"  
                    Grid.Row="1"  
                    materialDesign:HintAssist.Hint="Square Feet"  
                    materialDesign:HintAssist.IsFloating="True"  
                    Text="{Binding Building.SqF}">  

                    <behaviours:Interaction.Triggers>  
                        <behaviours:EventTrigger EventName="PreviewTextInput">  
                            <behaviours:InvokeCommandAction Command="{Binding ValidateNumberCommand}" PassEventArgsToCommand="True" />  
                        </behaviours:EventTrigger>  
                    </behaviours:Interaction.Triggers>  
                </TextBox>  

                <TextBox  
                    x:Name="BathTx"  
                    Grid.Row="2"  
                    materialDesign:HintAssist.Hint="Bathrooms"  
                    materialDesign:HintAssist.IsFloating="True"  
                    Text="{Binding Building.Bathrooms}">  

                    <behaviours:Interaction.Triggers>  
                        <behaviours:EventTrigger EventName="PreviewTextInput">  
                            <behaviours:InvokeCommandAction Command="{Binding ValidateNumberCommand}" PassEventArgsToCommand="True" />  
                        </behaviours:EventTrigger>  
                    </behaviours:Interaction.Triggers>  
                </TextBox>  

                <TextBox  
                    x:Name="BedTx"  
                    Grid.Row="3"  
                    materialDesign:HintAssist.Hint="Bedrooms"  
                    materialDesign:HintAssist.IsFloating="True"  
                    Text="{Binding Building.Bedrooms}">  

                    <behaviours:Interaction.Triggers>  
                        <behaviours:EventTrigger EventName="PreviewTextInput">  
                            <behaviours:InvokeCommandAction Command="{Binding ValidateNumberCommand}" PassEventArgsToCommand="True" />  
                        </behaviours:EventTrigger>  
                    </behaviours:Interaction.Triggers>  
                </TextBox>  

                <TextBox  
                    x:Name="DescTx"  
                    Grid.Row="5"  
                    HorizontalContentAlignment="Stretch"  
                    materialDesign:HintAssist.Hint="Description"  
                    materialDesign:HintAssist.IsFloating="True"  
                    Text="{Binding Building.Desc}"  
                    TextWrapping="Wrap">  

                    <behaviours:Interaction.Triggers>  
                        <behaviours:EventTrigger EventName="PreviewTextInput">  
                            <behaviours:InvokeCommandAction Command="{Binding ValidateTextCommand}" PassEventArgsToCommand="True" />  
                        </behaviours:EventTrigger>  
                    </behaviours:Interaction.Triggers>  
                </TextBox>  

                <StackPanel Grid.Row="4">  

                    <TextBox  
                        x:Name="AddressTx"  
                        materialDesign:HintAssist.Hint="Address"  
                        materialDesign:HintAssist.IsFloating="True"  
                        Text="{Binding Building.Address}" />  

                    <ListBox  
                        Grid.Row="4"  
                        VerticalAlignment="Bottom"  
                        d:ItemsSource="{d:SampleData ItemCount=5}" />  

                </StackPanel>  

                <Grid Grid.Row="6">  
                    <Grid.ColumnDefinitions>  
                        <ColumnDefinition Width="2*" />  
                        <ColumnDefinition Width="*" />  
                    </Grid.ColumnDefinitions>  

                    <TextBlock  
                        Margin="0,10,0,0"  
                        VerticalAlignment="Center"  
                        Focusable="False"  
                        Foreground="{StaticResource PlaceHolderColor}"  
                        Text="Select files" />  
                    <Button  
                        Grid.Column="1"  
                        Margin="10,10,0,0"  
                        Command="{Binding SearchPictureCommand}">  
                        <materialDesign:PackIcon Kind="Upload" />  
                    </Button>  

                </Grid>  

                <ListView  
                    Grid.Row="7"  
                    Margin="0,10,0,0"  
                    d:ItemsSource="{d:SampleData ItemCount=5}"  
                    ItemsSource="{Binding Building.FileNames}"  
                    ScrollViewer.CanContentScroll="True"  
                    ScrollViewer.VerticalScrollBarVisibility="Visible"  
                    SelectedItem="{Binding SeletedItem}">  
                    <ListView.ItemTemplate>  
                        <DataTemplate>  
                            <TextBlock Text="{Binding FileName}" />  
                        </DataTemplate>  
                    </ListView.ItemTemplate>  
                </ListView>  

            </StackPanel>  

            <Image  
                Grid.Column="1"  
                Width="360"  
                Height="360"  
                Margin="10"  
                VerticalAlignment="Top"  
                Source="/Views/Alan Wake Remastered 1_26_2022 1_32_16 AM.png" />  

            <Button  
                Grid.Column="1"  
                Height="50"  
                HorizontalAlignment="Right"  
                VerticalAlignment="Bottom"  
                BorderBrush="{x:Null}"  
                Command="{Binding SendCommand}"  
                Style="{StaticResource MaterialDesignFloatingActionButton}">  

                <Button.Content>  
                    <materialDesign:PackIcon  
                        Width="40"  
                        Height="40"  
                        Kind="Plus" />  
                </Button.Content>  
                <Button.IsEnabled>  
                    <MultiBinding Converter="{StaticResource hasText}">  
                        <Binding ElementName="NameTxt" Path="Text" />  
                        <Binding ElementName="SqTx" Path="Text" />  
                        <Binding ElementName="BathTx" Path="Text" />  
                        <Binding ElementName="BedTx" Path="Text" />  
                        <Binding ElementName="DescTx" Path="Text" />  
                        <Binding ElementName="AddressTx" Path="Text" />  
                        <Binding ElementName="BedTx" Path="Text" />  
                    </MultiBinding>  
                </Button.IsEnabled>  
            </Button>  
        </Grid>  
    </Border>  

app https://github.com/eduardoagr/RsidentsManager

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,169 questions
No comments
{count} votes

Accepted answer
  1. answered 2022-06-28T03:29:09.963+00:00
    Hui Liu-MSFT 14,561 Reputation points Microsoft Employee

    If you put a ListView inside a StackPanel, for example, the ListView's height can exceed the height of the StackPanel.
    The ListView has increased its height to show all its items, as far as it's concerned, thus no scrollbar.

    1. You could set height for ListView.
       <ListView      Height="170"  
                           Grid.Row="7" Margin="0,10,0,0"   
                           d:ItemsSource="{d:SampleData ItemCount=5}"  
                           ItemsSource="{Binding Building.FileNames}" ScrollViewer.CanContentScroll="True"  
                           ScrollViewer.VerticalScrollBarVisibility="Visible"  
                           SelectedItem="{Binding SeletedItem}">  
                          <ListView.ItemTemplate>  
                              <DataTemplate>  
                                  <TextBlock Text="{Binding FileName}" />  
                              </DataTemplate>  
                          </ListView.ItemTemplate>  
                      </ListView>  
      
      The result:

    215554-image.png

    2 . If you change that StackPanel to a Grid.
    Grid don't set last row (contains TabControl) height to auto as this will give enough space for TabControl to fit whole ListView without scrolling.

        <Grid>  
                <Grid.RowDefinitions>  
                    <RowDefinition Height="auto"/>  
                    <RowDefinition Height="auto"/>  
                    <RowDefinition Height="auto"/>  
                    <RowDefinition Height="auto"/>  
                    <RowDefinition Height="auto"/>  
                    <RowDefinition Height="auto"/>  
                    <RowDefinition Height="auto"/>  
                    <RowDefinition />  
                </Grid.RowDefinitions>  
                <TextBox  
                     x:Name="NameTxt"  
                     VerticalContentAlignment="Center"  
                     Text="{Binding Building.Name}">  
                </TextBox>  
                <TextBox  
                     x:Name="SqTx"  
                     Grid.Row="1"  
                     Text="{Binding Building.SqF}">  
                </TextBox>  
                <TextBox  x:Name="BathTx"   Grid.Row="2"  Text="{Binding Building.Bathrooms}">  
                </TextBox>  
    
                <TextBox   x:Name="BedTx"    Grid.Row="3"    Text="{Binding Building.Bedrooms}"></TextBox>  
                <TextBox x:Name="DescTx"  Grid.Row="5"  HorizontalContentAlignment="Stretch"  Text="{Binding Building.Desc}"   TextWrapping="Wrap">  
                </TextBox>  
                <StackPanel Grid.Row="4">  
                    <TextBox  x:Name="AddressTx"  Text="{Binding Building.Address}" />  
                    <ListBox    Grid.Row="4"   VerticalAlignment="Bottom"    d:ItemsSource="{d:SampleData ItemCount=5}" />  
                </StackPanel>  
    
                <Grid Grid.Row="6">  
                    <Grid.ColumnDefinitions>  
                        <ColumnDefinition Width="2*" />  
                        <ColumnDefinition Width="*" />  
                    </Grid.ColumnDefinitions>  
                    <TextBlock  
                         Margin="0,10,0,0"  
                         VerticalAlignment="Center"  
                         Focusable="False"  
                         Foreground="Purple"  
                         Text="Select files" />  
                    <Button    Grid.Column="1"   Margin="10,10,0,0"   Command="{Binding SearchPictureCommand}">+ </Button>  
                </Grid>  
                <ListView Height="170"  
                     Grid.Row="7" Margin="0,10,0,0"   
                     d:ItemsSource="{d:SampleData ItemCount=5}"  
                     ItemsSource="{Binding Building.FileNames}" ScrollViewer.CanContentScroll="True"  
                     ScrollViewer.VerticalScrollBarVisibility="Visible"  
                     SelectedItem="{Binding SeletedItem}">  
                    <ListView.ItemTemplate>  
                        <DataTemplate>  
                            <TextBlock Text="{Binding FileName}" />  
                        </DataTemplate>  
                    </ListView.ItemTemplate>  
                </ListView>  
    
            </Grid>  
    

    The result:

    215526-image.png


    If the response is helpful, please click "Accept Answer" and upvote it.
     Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread. 

    [5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html

    No comments

0 additional answers

Sort by: Most helpful