Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未为ListView启用ScrollViewer_C#_Wpf_Xaml_Listview_Scrollview - Fatal编程技术网

C# 未为ListView启用ScrollViewer

C# 未为ListView启用ScrollViewer,c#,wpf,xaml,listview,scrollview,C#,Wpf,Xaml,Listview,Scrollview,我在UserControl中有一个ListView控件。但当内容溢出ListView的大小时,垂直ScrollBar不会启用,尽管在XAML中进行了设置 XAML显示如下: <UserControl x:Class="GrandSuccessProject.View.ContactsView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

我在
UserControl
中有一个
ListView
控件。但当内容溢出
ListView
的大小时,垂直
ScrollBar
不会启用,尽管在XAML中进行了设置

XAML显示如下:

<UserControl x:Class="GrandSuccessProject.View.ContactsView"
             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="367" d:DesignWidth="548" Background="{x:Null}" VerticalContentAlignment="Top">

<ListView ScrollViewer.CanContentScroll="True" 
          ScrollViewer.VerticalScrollBarVisibility="Visible" 
          ItemsSource="{Binding SelectedContacts}"  
          ItemContainerStyle="{StaticResource ContainerStyle}" 
          Grid.Row="1" 
          VerticalAlignment="Top" 
          VerticalContentAlignment="Top" />      
   
</UserControl>

我还尝试将
列表视图
分组到
滚动查看器
中,但仍然不起作用

提前非常感谢:)

这看起来像

  • ListView占用了所有项目所需的所有空间,因此禁用了滚动
  • ListView超出了其容器的界限

  • 所以我假设容器没有限制ListView的大小,这是错误的,您把它放在哪里了?确保容器对控件的布局有限制。

    我将高度和宽度从主窗口传递到用户控件:

     <UC:UC Width="{Binding ElementName=GridMainWindow, Path=ActualWidth}" 
        Height="{Binding ElementName=GridMainWindow, Path=ActualHeight}"/>
    
    
    
    在usercontrol中,我定义了一个Gridview,如下所示:

    <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" /> <!--This inherith from the window-->
    </Grid.ColumnDefinitions>
    
    
    
    你完全正确,如果我为ListView保留固定的像素高度,滚动条会工作。@Marshal:有些地方不对劲,但如果没有所有上下文,很难判断UserControl上设置了哪些属性?@Marshal:请参见编辑,还没有测试它,但我怀疑您做了类似的事情,这可能就是问题所在…我尝试删除VerticalContentAlignment属性,但仍然没有effect@Marshal:很明显,设计高度限制了尺寸并可能导致溢出,但在运行时也会失败,不是吗?因为我无法用给定的代码重现这一点,您能否构造一个这样的示例?如果你试图把它归结起来,你甚至可能会注意到问题出在你自己身上。