简体   繁体   English

WPF中的多个绑定

[英]Multiple Bindings In WPF

Is it possible to have multiple item source bindings in xaml on a wpf control. 在wpf控件上是否可以在xaml中具有多个项目源绑定。

Currently I am using mvvm pattern and have an item binding that is bound to one object type. 当前,我正在使用mvvm模式,并且具有绑定到一种对象类型的项目绑定。

ItemSource="{Binding ProcessModel}"

this then has a ItemTemplate 然后有一个ItemTemplate

ItemTemplate="{DynamicResource PMDataTemplete}"

This currently is fine as I was only using one type of object. 目前这很好,因为我只使用一种类型的对象。 I want to extend this so I can have one or a 2nd different type of object, but it does not need to be able to bind to both at the same time. 我想对此进行扩展,这样我就可以拥有一个或第二种不同类型的对象,但是不必同时绑定到两个对象。

What I am trying to achieve is the situation where one object type can be bound depending on what the user selects and the binding will work and again if the user takes a different route the other type of object is displayed on the same control. 我要实现的情况是,可以根据用户选择的内容绑定一种对象类型,绑定将起作用,并且如果用户采用不同的路线,则另一种对象类型将显示在同一控件上。

So it is almost the idea of having a case statement based on object types for the itemsource. 因此,几乎有一个想法是基于itemSource的对象类型创建case语句。

编写自己的ItemTemplateSelector (更灵活,但更复杂)或定义需要在ItemsControl中呈现的类型的数据模板。

There is two options: 有两种选择:

  1. You can define datatemplates for different types. 您可以为不同类型定义数据模板。
  2. You can write DataTemplateSelector as Dennis mentioned. 您可以如Dennis所述编写DataTemplateSelector。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM