【发布时间】:2013-08-16 12:34:14
【问题描述】:
我正在尝试研究如何将用户控件列表数据绑定到 WrapPanel,但我没有太多的运气搜索。
我对 WPF 很陌生(来自 WinForms),目前我在运行时将 UserControls 添加为子项。据我所知,WrapPanel 不支持数据绑定,是否有任何解决方案。
【问题讨论】:
标签: c# wpf data-binding wrappanel
我正在尝试研究如何将用户控件列表数据绑定到 WrapPanel,但我没有太多的运气搜索。
我对 WPF 很陌生(来自 WinForms),目前我在运行时将 UserControls 添加为子项。据我所知,WrapPanel 不支持数据绑定,是否有任何解决方案。
【问题讨论】:
标签: c# wpf data-binding wrappanel
试试这样的:
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding YourSource}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
...
</ListBox>
如果你不需要选择的东西,你可以尝试使用 ItemsControl。
<ItemsControl ItemsControlScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding YourSource}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
...
</ItemsControl>
【讨论】: