C# 包装内的ItemsControl未使用所有可用空间

C# 包装内的ItemsControl未使用所有可用空间,c#,wpf,C#,Wpf,itemscontrol中有许多元素。此itemscontrol位于scrollviewer中,scrollviewer的父级为Wrappanel。无论是否使用此scrollviewer,元素都将相互堆叠,并且永远不会使用所有可用空间。我做错了什么?包裹物在网格内 不太清楚您想要实现什么,但是一个使用WrapPanel布局其项的可滚动项控件应该如下所示: <ItemsControl ItemsSource="{Binding ...}"> <Ite

itemscontrol中有许多元素。此itemscontrol位于scrollviewer中,scrollviewer的父级为Wrappanel。无论是否使用此scrollviewer,元素都将相互堆叠,并且永远不会使用所有可用空间。我做错了什么?包裹物在网格内


不太清楚您想要实现什么,但是一个使用WrapPanel布局其项的可滚动项控件应该如下所示:

<ItemsControl ItemsSource="{Binding ...}">
    <ItemsControl.Template>
        <ControlTemplate TargetType="ItemsControl">
            <ScrollViewer
                HorizontalScrollBarVisibility="Disabled"
                VerticalScrollBarVisibility="Auto">
                <ItemsPresenter/>
            </ScrollViewer>
        </ControlTemplate>
    </ItemsControl.Template>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            ...
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

...

下添加
ItemsControl.ItemsPanel>
为我修复了它。
<ItemsControl ItemsSource="{Binding ...}">
    <ItemsControl.Template>
        <ControlTemplate TargetType="ItemsControl">
            <ScrollViewer
                HorizontalScrollBarVisibility="Disabled"
                VerticalScrollBarVisibility="Auto">
                <ItemsPresenter/>
            </ScrollViewer>
        </ControlTemplate>
    </ItemsControl.Template>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            ...
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>