ItemsControl包装窗口内的内容

Jim*_*mmy 2 wpf user-controls itemscontrol mvvm itemsource

ItemsControl在WPF中使用了一个窗口.itemscontrol与集合绑定,集合是一组视图模型(用户控件).我的问题 - 由于集合中的许多视图模型,视图超出了当前窗口.我用滚动条尝试了很多东西来处理它但没用.有什么建议?问题是如何在窗口中包含itemscontrol(滚动)?

下面的XAML

<Window x:Class="WpfApplicationTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:app="clr-namespace:WpfApplicationTest"
    Title="MainWindow" Height="350" Width="525">   
  <Grid Height="Auto">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="30"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <ItemsControl Grid.Row="0" Grid.Column="0" ItemsSource="{Binding UserControlCollection}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>           
    <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Bottom">
        <Button Content="OK" Width="100" Margin="3" />
        <Button Content="Cancel" Width="100" Margin="3" />
    </StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)

Bas*_*Bas 6

将您的数据包裹ItemsControlScrollViewer中

更新:在您的示例中,如果行高度无法正确缩放,也会将行高设置为*.