内容简介:http://stackoverflow.com/questions/5108235/wpf-listview-scrollbars本站文章除注明转载外,均为本站原创或编译转载请明显位置注明出处:WPF ListView滚动条
好的,我放弃了 – 如何让垂直滚动条出现在列表视图中,而不指定xaml中MaxHeight的硬编码值?
这是我的xaml(我没有包括数据模型,但它基本上是一个目录列表)
<UserControl x:Class="WpfApplication1.Views.FolderViewView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="500" > <DockPanel> <StackPanel DockPanel.Dock="Top"> <Label Name="lblFolder" Content="{Binding Path=FolderName}" MinWidth="250"/> <Button Name="btnFolder" Content="Select Folder" Click="btnFolder_Click" /> </StackPanel> <DockPanel> <ListView Name="lstFiles" ItemsSource="{Binding}" Margin="1" MaxHeight="200" Height="Auto" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" > <ListView.View> <GridView> <GridViewColumn Header="Filename" DisplayMemberBinding="{Binding Path=FileName}" /> <GridViewColumn Header="Extenstion" DisplayMemberBinding="{Binding Path=Extension}" /> <GridViewColumn Header="Size" DisplayMemberBinding="{Binding Path=FileSize}" /> <GridViewColumn Header="Creation Date" DisplayMemberBinding="{Binding Path=CreateDate}" /> <GridViewColumn Header="Modified Date" DisplayMemberBinding="{Binding Path=ModifiedDate}" /> </GridView> </ListView.View> </ListView> </DockPanel> </DockPanel>
没有在ListView控件上设置MaxHeight,当有足够的项目使列表视图大于屏幕时,滚动条不会出现.
使用MaxHeigt =“250”时,会出现滚动条,但是当用户更改窗口的大小时,列表视图现在不会扩展.
也许我提出错误的问题,应该是:当窗口的高度改变时,如何更改列表视图的最大高度?
请帮忙,这已经把我推到最后一天的墙上了…
谢谢
背风处
问题来自于DockPanel的使用.默认情况下,它给它的子项所需的空间(无论可用空间).
为了修复它,我建议您使用网格面板而不是DockPanel:
<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <StackPanel Grid.Row="0"> <Label Name="lblFolder" Content="{Binding Path=FolderName}" MinWidth="250"/> <Button Name="btnFolder" Content="Select Folder" Click="btnFolder_Click" /> </StackPanel> <ListView Grid.Row="1" Name="lstFiles" ItemsSource="{Binding}" Margin="1" > <ListView.View> <GridView> <GridViewColumn Header="Filename" DisplayMemberBinding="{Binding Path=FileName}" /> <GridViewColumn Header="Extenstion" DisplayMemberBinding="{Binding Path=Extension}" /> <GridViewColumn Header="Size" DisplayMemberBinding="{Binding Path=FileSize}" /> <GridViewColumn Header="Creation Date" DisplayMemberBinding="{Binding Path=CreateDate}" /> <GridViewColumn Header="Modified Date" DisplayMemberBinding="{Binding Path=ModifiedDate}" /> </GridView> </ListView.View> </ListView> </Grid>
http://stackoverflow.com/questions/5108235/wpf-listview-scrollbars
本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:WPF ListView滚动条
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。