简体   繁体   English

ValueConveter或DataTemplate

[英]ValueConveter or DataTemplate

I am trying to build a generic interface that can accept a List of objects and then based on the users selection of how they want to view the objects will select different ways of display the object. 我正在尝试构建一个可以接受对象列表的通用接口,然后根据用户对他们如何查看对象的选择来选择显示对象的不同方式。 Currently, the user has a dropdown that allows them to choose the view type such as "Details, Previews, etc" much like explorer and then based off the selection the display should change. 当前,用户有一个下拉菜单,使他们可以像浏览器一样选择视图类型,例如“详细信息,预览等”,然后根据选择内容,显示应该更改。 My first attempt at this was to create UserControls that will accept the bound object and display it, however I dont know how to convert my listitems into the user controls. 我的第一个尝试是创建将接受绑定对象并显示它的UserControls,但是我不知道如何将列表项转换为用户控件。 My question is, is should I be using IValueConverter to convert the listitem into the type of user control I want to display, or should I be using DataTemplates and a TemplateSelector to define my different views? 我的问题是,应该使用IValueConverter将listitem转换为要显示的用户控件类型,还是应该使用DataTemplates和TemplateSelector定义不同的视图?

Why not just use ListView and GridView? 为什么不只使用ListView和GridView? Your use case is exactly why they're there. 您的用例正是它们在那里的原因。

MSDN has a nice little sample for how to switch views in a ListView at runtime right here . MSDN对如何在ListView在运行时正确的切换视图一个可爱的小样品在这里

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

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