将数据模板选择器绑定到内容控制模板
我想将内容控件绑定到数据模板选择器,将变量绑定到该内容控件,然后根据变量包含的内容显示不同的模板。
我已经设法让 Telerik DataTemplateSelector
来执行我需要的操作,但是我找不到将 DataTemplateSelector
绑定到的控件。
我发现允许我使用 DataTemplateSelector
的所有控件都要求 ItemsSource
是一个集合,如果我传入单个对象,它会引发异常。
我传递的项目是单个项目而不是集合。内容控件似乎是我所需要的,但我无法将 DataTemplateSelector 绑定到它。
是否有类似于内容控件的 telerik 控件,我可以将 DataTemplateSelector 绑定到该控件?或者是否有类似于 DataTemplateSelector 的东西,我可以将其绑定到内容控件。
任何帮助将不胜感激。
I would like to bind a content control to a data template selector, bind a variable to that content control and then display a different template depending on what the variable contains.
I've managed to get a Telerik DataTemplateSelector
to do what I need it to, however I can't find a control to bind the DataTemplateSelector
to.
All of the controls that I've found that allow me to use a DataTemplateSelector
require the ItemsSource
to be a collection, if I pass in a single object it throws an exception.
The item I'm passing in is a single item not a collection. The content control seems to be what I need but i can't bind a DataTemplateSelector
to it.
Is there a telerik control similar to the Content Control, that I can bind a DataTemplateSelector to? Or is there something similar to a DataTemplateSelector
that I can bind to a Content Control.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你应该考虑避免 Telerik 的课程(在我看来,在这种情况下,这会让事情变得有点复杂)。
标准
DataTemplateSelector
实现怎么样?自己实现非常容易!
首先,您声明抽象类
DataTemplateSelector
的“经典”实现:然后您可以编写自定义
DataTemplateSelector
......最后XAML 设计(不是通常的 ListBoxItem,而是本例中的可滚动内容):
I think you should consider avoiding Telerik's classes (which, in my opinion, complicate the things a bit in this case).
What about a standard
DataTemplateSelector
implementation?It's very easy to implement by yourself!
First you declare a "classic" implementation of the abstract class
DataTemplateSelector
:Then you can write you custom
DataTemplateSelector
......and finally the XAML designing (not the usual ListBoxItem, but a scrollable content in this case):