WrapPanel与ItemControl一起使用时不包装

问题描述 投票:2回答:1

我有一个用UserControls填充ViewModel的WrapPanel:

<WrapPanel Width="250" Orientation="Horizontal" Margin="3">
   <ItemsControl ItemsSource="{Binding PlaceableObjectsContent}">
      <ItemsControl.ItemTemplate>
          <DataTemplate DataType="{x:Type local:PlaceableObjectViewModel}">
              <local:PlaceableObjectUserControl>
                 <local:PlaceableObjectUserControl.InputBindings>
                     <MouseBinding MouseAction="LeftClick"
                                                  Command="{Binding DataContext.OnPlaceableObjectClicked, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
                                                  CommandParameter="{Binding}"/>
                 </local:PlaceableObjectUserControl.InputBindings>
              </local:PlaceableObjectUserControl>
          </DataTemplate>
      </ItemsControl.ItemTemplate>
   </ItemsControl>
</WrapPanel>

当我用随机控件填充它们时,一切正常!由于使用ItemTemplate,我已经阅读了一些有关问题的信息!如果属实,我该如何处理?

谢谢

c# wpf itemscontrol itemtemplate wrappanel
1个回答
4
投票
请注意,有些东西必须限制ItemsControl的宽度才能正常工作:要么必须受其父项或Grid Column的大小的限制,要么必须通过设置ItemsControl元素本身的Width或MaxWidth属性来对其进行限制,直接或通过样式。
© www.soinside.com 2019 - 2024. All rights reserved.