![](/img/trans.png)
[英]How to add empty UserControl of StackPanel programmatically in WPF
[英]How to binding UserControl in a StackPanel?
我的问题很简单,我可以从 LinkedList 中的元素在 StackPanel 中使用绑定吗? 在我的应用程序中,LinkedList 中元素的顺序很重要。 可能元素可以动态更改其在 LinkedList 中的位置。 我想知道是否可以绑定我的 LinkedList,以便我的应用程序始终以正确的顺序显示元素,而无需任何额外的 C# 代码/事件触发器。
可以在 WPF 中做到这一点吗?
我该如何实施?
只需将ItemsControl
的ItemsSource
属性设置或绑定到您的链接列表:
ic.ItemsSource = yourList;
...并可选择为ItemsControl
定义自定义ItemsPanelTemplate
:
<ItemsControl x:Name="ic">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.