2011-11-29 93 views
2

我一直在研究這個很長一段時間,找不到答案。ItemsControl DataTemplate並排顯示的項目

我該如何顯示項目控件中的每個項目?

以下代碼並排顯示每個項目的內容(標籤和文本框),但下面的項目顯示在下面。假設我在ItemsControl中有3個項目。目前的行爲是:

標籤文本框
標籤文本框
標籤文本框

我想要的是:

標籤文本框標籤的文本框的標籤文本框(並排)

當前的代碼使用堆棧面板whick設置方向爲水平(這就是爲什麼標籤和文本框是並排的)。但我需要一些屬性或技術來將itemscontrol內容方向設置爲水平。我的代碼:

<ItemsControl.ItemTemplate> 
    <DataTemplate> 
      <StackPanel Name="pnlText" Orientation="Horizontal" Width="750"> 
       <Label Content="{Binding ParameterDisplayName, Mode=OneWay}" /> 
       <TextBox Name="txtText" HorizontalAlignment="Left" Text="{Binding ParameterValue, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" Visibility="{Binding ParameterType, Converter={StaticResource ParameterTypeToVisibilityConverter}, ConverterParameter=Text}" /> 
      </StackPanel> 
    </DataTemplate> 
</ItemsControl.ItemTemplate> 

有誰知道該怎麼做?

謝謝!

回答

3

你應該設置該屬性爲您ItemsControl

<ItemsControl.ItemsPanel> 
    <ItemsPanelTemplate> 
    <StackPanel Orientation="Horizontal" /> 
    </ItemsPanelTemplate> 
</ItemsControl.ItemsPanel> 
+1

感謝隊友。這麼簡單,但很難找到設置它的地方。乾杯 –

相關問題