ItemsControl DataTemplate项并排显示 [英] ItemsControl DataTemplate Items showing side by side

查看:385
本文介绍了ItemsControl DataTemplate项并排显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经研究了很长时间,找不到答案.

I've been researching this for quite long time now, can't find the answer.

如何在项控件中并排显示每个项?

How can I display each item in my itemscontrol side by side?

以下代码并排显示每个项目的内容(标签和文本框),但下一个项目显示在下面.假设我的ItemsControl中有3个项目.当前行为是:

The following code displays each item's content side by side (label and textbox), but the next item is shown underneath. Let's say I have 3 items in my ItemsControl. The current behaviour is:

标签文本框
标签文字框
标签文字框

Label Textbox
Label Textbox
Label Textbox

我想要的是:

标签文本框标签文本框标签文本框(并排)

Label Textbox Label Textbox Label Textbox (side by side)

当前代码使用堆栈面板鞭将方向设置为水平(这就是标签和文本框并排放置的原因).但是我需要一些属性或技术来将ItemsControl的内容方向设置为水平.我的代码:

The current code uses a stack panel whick sets the orientation to horizontal (that's why the label and textbox are side by side). But I need some property or technique to set the itemscontrol content orientation to horizontal. My code:

<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>

有人知道怎么做吗?

谢谢!

推荐答案

您应为ItemsControl设置此属性:

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

这篇关于ItemsControl DataTemplate项并排显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆