根据类型动态更改XAML绑定 [英] Dynamically change XAML binding based on type

查看:52
本文介绍了根据类型动态更改XAML绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象列表,这些对象被用作DataGrid的源。该对象列表是基类类型,其中有2个或更多继承类型。我试图绑定到基类的属性以在DataGrid列中显示为值。子类具有可供我显示的不同属性,所以我的问题是,XAML是否可以根据所指向的类型动态更改绑定的值?我曾考虑过可能使用转换器执行此操作,但是如果我理解正确,那么我将不得不为需要绑定到的每个子类属性编写一个不同的转换器。任何意见或建议,表示赞赏。谢谢

I have a list of objects that is being used as the source for a DataGrid. This list of objects is a base class type, of which there are 2 or more inherited types. I am trying to bind to properties of the base class to display as values in the columns of the DataGrid. The subclasses have different properties available to them which I would like to be able to display, so my question is, does XAML have a way to dynamically change the value of a binding based on the type that is being pointed to? I have thought about potentially doing this with a converter, but if I understand correctly, then I would have to write a different converter for each subclass property that I need to bind to. Any advice or suggestions are appreciated. Thanks

推荐答案

实现此目标的方法是CellTemplateSelector。
请参阅此链接

The means to achieve this would be a CellTemplateSelector. See this link.

这篇关于根据类型动态更改XAML绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆