2015-10-27 29 views
2

我使用ListBox来显示我认为的ObservableCollection的内容。在我简单的例子,我只是用图像像每个项目:使用ListBox和StackPanel的所有可用空间作为ItemsPanelTemplate

<Window> 
    <Window.Resources> 
     <DataTemplate DataType="{x:Type viewModel:HealthCriterionViewModel}"> 
      <Image VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Source="Optionsh.png" Stretch="Fill" /> 
     </DataTemplate> 
    </Window.Resources> 

    <ListBox ItemsSource="{Binding HealthCriteria}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
    </ListBox> 
</Window> 

HealthCriteriaHealthCriterionViewModel类型的集合。

我得到的是这样的:

enter image description here

我想是这样的(拉伸图像水平和垂直方向使用所有可用空间):

enter image description here

我怎样才能做到这一点?

回答

1

我建议你不能用ItemsControl来实现它。由于内容演示者大小不固定,因此它是可滚动区域。所以每个元素的大小应该是固定的。它可以直接在ItemsPanel中用“重量”或“高度”(取决于方向)属性或受内容大小限制。

相关问题