Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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
Wpf ScrollViewer中的自动调整列表框大小_Wpf_Xaml_Listview_User Controls_Scrollviewer - Fatal编程技术网

Wpf ScrollViewer中的自动调整列表框大小

Wpf ScrollViewer中的自动调整列表框大小,wpf,xaml,listview,user-controls,scrollviewer,Wpf,Xaml,Listview,User Controls,Scrollviewer,在我的应用程序中,我有一个窗口。它包含左侧菜单、标题和内容位置 此内容正在动态加载-一个UserControl放入其中。这些UserControls是各种各样的。从一个TextBlock到相当复杂的页面。为了确保所有内容都可见,我必须用ScrollViewer(我的意思是在MyWindow.xaml中)将其包装起来。在我需要在内容中添加ListView之前,一切正常 代码大致如下所示: <ScrollViewer> // this is the wrapping viewer act

在我的应用程序中,我有一个
窗口
。它包含左侧菜单、标题和内容位置

此内容正在动态加载-一个
UserControl
放入其中。这些
UserControls
是各种各样的。从一个
TextBlock
到相当复杂的页面。为了确保所有内容都可见,我必须用
ScrollViewer
(我的意思是在MyWindow.xaml中)将其包装起来。在我需要在内容中添加
ListView
之前,一切正常

代码大致如下所示:

<ScrollViewer> // this is the wrapping viewer actually it's in a different file
    <UserControl>
        ......
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="10*"/>
                <ColumnDefinition Width="20*"/>
            </Grid.ColumnDefinitions>
            <ListView  ItemsSource="{Binding Entities}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock Style="{StaticResource Value}" Text="{Binding WorkOrderNumber}"/>
                            <TextBlock Style="{StaticResource Value}" Text="{Binding ActionType}"/>
                            <TextBlock Style="{StaticResource Value}" Text="{Binding StartDate}"/>
                            <TextBlock Style="{StaticResource Value}" Text="{Binding StopDate}"/>
                            <Separator/>
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <Whatever.. Grid.Row="0" Grid.Column="1"/>
            <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
                <Button Style="{StaticResource CustomButton}" Content="Previous" />
                <Button Style="{StaticResource CustomButton}" Content="Current" />
                <Button Style="{StaticResource CustomButton}" Content="Next" />
            </StackPanel>
        </Grid>
    </UserControl>
</ScrollViewer>
//这是包装查看器,实际上它位于不同的文件中
......
结果是listbox没有滚动条,变高了。滚动条仅位于窗口的滚动查看器中

因此,在我的UserControl中,我希望:

  • 按钮总是在最下面
  • 列表框以填充剩余的整个空间(也可随窗口一起调整大小)
  • 避免硬编码列表框的高度

这可能吗?

使用DockPanel而不是网格。DockPanel有一个名为LastChhildFill的属性。默认情况下这是真的。如果将列表框设置为最后一个子项,它将填充所有空间:

<ScrollViewer>
    <DockPanel>
        <StackPanel DockPanel.Dock="Bottom"
                    Orientation="Horizontal"
                    HorizontalAlignment="Center">
            <Button Style="{StaticResource CustomButton}"
                    Content="Previous" />
            <Button Style="{StaticResource CustomButton}"
                    Content="Current" />
            <Button Style="{StaticResource CustomButton}"
                    Content="Next" />
        </StackPanel>
        <ListView >
        </ListView>
    </DockPanel>
</ScrollViewer>

但此设置会使按钮消失。我的意思是,它们总是在列表框的底部。因此,您可能需要删除ScrollViewer