Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何在一个模板中绑定多个ListView?_Wpf_Mvvm_Controltemplate - Fatal编程技术网

Wpf 如何在一个模板中绑定多个ListView?

Wpf 如何在一个模板中绑定多个ListView?,wpf,mvvm,controltemplate,Wpf,Mvvm,Controltemplate,我有一个用于3个列表视图的控件模板。 我正在列表视图上使用模板,例如 Template="{StaticResource listViewTemplate}" 当我尝试将集合绑定到列表视图项资源时,什么都没有发生。 如果我绑定ControlTemplate的Collection ItemsSource,它就可以正常工作 问题是我有3个使用此ControlTemplate的ListView,我想将3个不同的集合绑定到ListView 这可能吗?将x:Shared=“False”添加到静态资源中。

我有一个用于3个列表视图的控件模板。 我正在列表视图上使用模板,例如

Template="{StaticResource listViewTemplate}"
当我尝试将集合绑定到列表视图项资源时,什么都没有发生。 如果我绑定ControlTemplate的Collection ItemsSource,它就可以正常工作

问题是我有3个使用此ControlTemplate的ListView,我想将3个不同的集合绑定到ListView

这可能吗?

x:Shared=“False”
添加到静态资源中。这将确保每次请求资源时都创建对象的浅层副本

这样,每个ListView将获得不同的控件模板实例


下面是它的文档:

您的控件模板需要使用TemplateBinding来绑定其ItemsSource

<ControlTemplate ...>
    <ItemsSource = "{templateBinding ItemsSource}"


你能添加更多不适合你的xaml吗?需要更多信息,向我们展示你的模板和整个列表声明,以及你的ItemSource是什么类型-ObervableCollection List,Dictionary?在这种情况下,通常,最好创建一个原型,尝试用最少的标记和代码做您想要做的事情。你不仅可以用它来创造一个非常好的问题,而且你还可以在提问之前解决你的问题。