我已经研究了很长时间了,找不到答案。
如何并排显示 itemscontrol 中的每个项目?
以下代码并排显示每个项目的内容(标签和文本框),但下一个项目显示在下方。假设我的 ItemsControl 中有 3 个项目。当前行为是:
标签文本框
标签文本框
标签文本框
我想要的是:
标签文本框标签文本框标签文本框(并排)
当前代码使用一个堆栈面板,它将方向设置为水平(这就是标签和文本框并排的原因)。但我需要一些属性或技术来将 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>
有人知道怎么做吗?
谢谢!
最佳答案
您应该为您的 ItemsControl
设置此属性:
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
关于wpf - 并排显示的 ItemsControl DataTemplate 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8308903/