我目前正在使用Wpf应用程序。 我有一个名为SearchFilters.I的用户控件,我想将usercontrol的集合绑定到mainWindow的stackpanel的子项,这意味着要将所有的usercontrols作为stackpanel的子项。我如何实现这一点? 请帮忙!将USercontrol的集合绑定到Stackpanel
1
A
回答
1
试试这个,在主窗口
<ItemsControl ItemsSource="{Binding YourBindableCollection}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:YourUserControl />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
YourUserControl必须在同一文件夹作为主窗口,如果你想保留当地作为命名空间
+1
为什么一个ListView?在问题中没有提到项目应该是可选择的,或者可能显示为列。您应该通过ItemsControl替换ListView。也绝对不需要“YourUserControl必须与MainWindow位于同一文件夹中”。它仅取决于如何声明XML名称空间“local”。用户控件也可以放在不同的程序集中。 – Clemens
+0
@Clemens我同意,ListView可以被ItemsControl替换。在评论中,用户说他是WPF的新手,所以我在最后指定了注释,因为我使用了本地名称空间。 –
相关问题
- 1. UserControl不会显示绑定的集合
- 2. 将datagrid绑定到集合
- 3. 将UserControl绑定到NULL DataContext
- 4. 将ItemsControl绑定到ViewModel的ViewModel集合
- 5. 将UserControl中ImageBrush的ImageSource绑定到CodeBehind
- 6. 将ObservableCollection项绑定到WrapPanel中的UserControl?
- 7. 将事件绑定到WPF中的UserControl
- 8. 绑定的BindingList到集合
- 9. 绑定到DataGridView的集合
- 10. 如何将WPF Datagrid的itemssource绑定到集合的集合?
- 11. 将数据网格绑定到集合中的嵌套集合
- 12. 将TabControl绑定到ViewModels集合
- 13. 将二维集合绑定到DataGridView
- 14. 将集合绑定到列表框
- 15. 将字符串集合绑定到FlowDocument
- 16. 将ListView绑定到集合IComparable
- 17. 将可观察集合绑定到GridView
- 18. 将Silverlight TabControl绑定到集合
- 19. 将对象绑定到XAML集合
- 20. 将数据绑定到集合
- 21. 绑定到UserControl的DependencyProperty
- 22. 从itemscontrol到usercontrol的绑定
- 23. WPF将树视图绑定到UserControl
- 24. 将依赖属性绑定到usercontrol
- 25. 将UserControl卸载事件绑定到ViewModel
- 26. 如何将usercontrol属性绑定到Listbox
- 27. 将Silverlight UserControl绑定到复杂对象
- 28. 将XML文件绑定到UserControl
- 29. 将StackPanel中的列表框的高度绑定到StackPanel的高度
- 30. wpf usercontrol,将按钮的命令参数绑定到父usercontrol
如果你有相同的用户控件类的多个实例,使用ItemsControl并将UserControl放在其“ItemTemplate”中。在这个DataTemplate中,将UserControl的属性绑定到视图模型项目类的属性。 – Clemens
其实我是WPF的新手,你能给我一个例子吗?谢谢。@ Clemens –
我只有一个UserControl,我想创建一个usercontrol实例的列表,并且想把这个列表绑定到stackpanel的子节点上。 –