简体   繁体   English

滚动永远不会出现在ListView中

[英]Scroll never appears in ListView

    <Grid>  
<Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
          <ListView  Grid.Row="1" Margin="0" Background="Transparent"  ItemsSource="{Binding Path=HistoryList, Mode=OneWay}"  Name="leftPanelScrollViewer" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <Border Background="{Binding Background}" Tag="{Binding Id}" ContextMenuOpening="FrameworkElement_OnContextMenuOpening" ContextMenuClosing="FrameworkElement_OnContextMenuClosing" ContextMenuService.HasDropShadow="True" ContextMenuService.Placement="Bottom" ContextMenuService.PlacementTarget="{Binding ElementName=PersonNameHistoryItem}"  Padding="10 80" CornerRadius="3" BorderThickness="0" Margin="5,0,5,5" MouseLeftButtonUp="Item_OnMouseDown">
                                                <Grid Background="Transparent">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition  />
                                                    </Grid.ColumnDefinitions>
                                                    <Image Grid.Column="0" VerticalAlignment="Top" Width="44" Height="44" Source="/Size.WPF;component/Assets/default-avatar.png" />
        ...
                                               </Grid>
                                            </Border>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
    </Grid>  

I have this code in WPF App. 我在WPF应用程序中有此代码。

Problem - scroll never appears. 问题-滚动永远不会出现。 Instead of adding scroll ListView make Height bigger. 而不是添加滚动ListView使Height更大。

The same with ListBox . ListBox相同。

When I don't need scroll it looks like and When I need scroll it looks like 当我不需要把它的滚动的样子 当我需要滚动它看起来像

在此处输入图片说明 在此处输入图片说明


In what wrapped ListBox : Page > Grid ( 在包装ListBoxPage > Grid

<Grid.RowDefinitions>
            <RowDefinition Height="90"  />
            <RowDefinition Height="780" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

) > Grid ( Grid.RowSpan="3" )> Border > Grid ( <RowDefinition Height="*" /> ) > ListView )> GridGrid.RowSpan="3" )> Border > Grid<RowDefinition Height="*" /> )> ListView

You've probably got the grid inside a stack panel or some other control that's unbound in size. 您可能已经将网格放在堆栈面板或其他大小不受限制的控件中。

Stack panels grow to what ever size their content needs. 堆叠面板的大小可以满足其内容需求。

You need to either restrict the maximum size of the stack panel or remove it altogether. 您需要限制堆栈面板的最大尺寸或将其完全删除。

Once you've done that the scrollbar should appear. 完成后,滚动条应会出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM