如何在单个模板中绑定多个 ListView?
我有一个用于 3 个 ListView 的 ControlTemplate。 我在 ListView 上使用模板,例如。
Template="{StaticResource listViewTemplate}"
当我尝试将 Collection 绑定到列表视图 ItemsSource 时,什么也没有发生。 如果我绑定 ControlTemplate 的 Collection ItemsSource 它工作正常。
问题是我有 3 个 ListView 使用此 ControlTemplate,并且我想将 3 个不同的集合绑定到 ListView。
这可能吗?
I have a ControlTemplate for 3 ListViews.
Im Using the Template on a ListView eg.
Template="{StaticResource listViewTemplate}"
When i try to bind a Collection to the list views ItemsSource nothing happents.
If i Bind the Collection ItemsSource of the ControlTemplate it works fine.
The Problem is i have 3 ListViews using this ControlTemplate and i want to bind 3 different collections to the ListViews.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的控件模板需要使用 TemplateBinding 绑定其 ItemsSource,例如,
这将使您能够在列表视图 ItemSource 上绑定集合(这将传递到 ControlTemplates ItemsSource)
Your control template needs to bind its ItemsSource using TemplateBinding eg
That will enable you to bind a collection on the list views ItemSource (this will get passed on to the ControlTemplates ItemsSource)
将
x:Shared="False"
添加到您的静态资源。这将确保每次请求资源时都会创建对象的浅表副本。这样,每个 ListView 将获得控件模板的不同实例。
以下是有关它的文档: http://msdn.microsoft.com/en-我们/library/aa970778.aspx
Add
x:Shared="False"
to your static resource. This will make sure a shallow copy of the object is made every time you request the resource.This way each of your ListViews will get a different instance of the control template.
Here is the documentation on it: http://msdn.microsoft.com/en-us/library/aa970778.aspx