WPF 中是否有某种方式可以获得与DataTemplateSelector
您相同的功能,但对于 UserControls?
假设我有一个 StackView,我想将一个 IEnumerable 对象绑定到该 StackView。我想做的是以某种方式有一个映射,对于绑定的 IEnumerable 中的每个对象类型,查看对象类型并确定要添加到 StackView 的 UserControl。
因此,给定三个类:
public class House : Building{}
public class Apartment : Building{}
public class Tent : Building{}
每个类都继承自Building
并定义了自己的类UserControl
,我想设置DataContext
为 anIEnumerable<Building>
并以某种方式让 StackView 使用特定于类型的 UserControl 填充其子集。
我想用尽可能少的代码来做到这一点。数据绑定和 XAML 管道磁带越多越好。