DockPanel ItemsControl lastchild填充

tbi*_*hel 0 c# wpf itemscontrol fill dockpanel

我有一个dockpanel,我使用ItemsControl动态填充以填充面板.dockpanel需要来自itemscontrol列表的最后一个子节点来填充面板的其余部分,但是如果我以这种方式填充它似乎不会发生...我该怎么做才能让最后一个项目扩展?

我如何设置它的片段:(注意我将dockpanel背景设置为蓝色,以便我可以区分填充的用户控件和面板的背景)

        <DockPanel Background="Blue" LastChildFill="True" Margin="0">
        <ItemsControl ItemsSource="{Binding Requirements}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <local:TMGrid2View Baseline="{Binding}"/>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </DockPanel>
Run Code Online (Sandbox Code Playgroud)

我目前关于发生了什么的假设是将子填充应用于itemscontrol而不是itemscontrol中填充的子代.我过去曾经使用过setter来指定孩子应该停靠在面板的一侧......例如,似乎没有一个子设置器选项来让它扩展...

Rob*_*ney 6

不要把ItemsControlDockPanel; 把它放进DockPanelItemsControl.用它ItemsPanelTemplate来制作ItemsControl它的物品DockPanel.

使用它ItemContainerStyle来设置DockPanel.Dock项容器的属性(对于an ItemsControl,将是ContentPresenters).

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:sys="clr-namespace:System;assembly=mscorlib">
  <ItemsControl Margin="5">
    <ItemsControl.ItemsPanel>
      <ItemsPanelTemplate>
        <DockPanel LastChildFill="True"/>
      </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemContainerStyle>
      <Style TargetType="ContentPresenter">
        <Setter Property="DockPanel.Dock" Value="Top"/>
      </Style>
    </ItemsControl.ItemContainerStyle>
    <ItemsControl.ItemTemplate>
      <DataTemplate>
        <TextBlock Background="Lavender" Margin="1" Padding="5" Text="{Binding}"/>
      </DataTemplate>
    </ItemsControl.ItemTemplate>
    <sys:String>Athos</sys:String>
    <sys:String>Porthos</sys:String>
    <sys:String>Aramis</sys:String>
    <sys:String>D'Artagnan</sys:String>
  </ItemsControl>
</Page>
Run Code Online (Sandbox Code Playgroud)