热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ListView:在资源字典中定义ItemsPanelTemplate-ListView:defineItemsPanelTemplateinresourcedictionary

IhaveaListViewwhichlayoutlookslikeaWindowsExplorerview(icon+somedetails),boundtoa

I have a ListView which layout looks like a Windows Explorer view (icon + some details), bound to a list somewhere in the ViewModel.

我有一个ListView,它的布局看起来像Windows资源管理器视图(图标+一些细节),绑定到视图模型中的某个列表。

My aim here is to be able to switch between explorer view or classic view whenever we want.

我的目标是在我们想要的时候能够在explorer视图或经典视图之间切换。

I could define an ItemsPanelTemplate doing exactly the work to display correctly the layout, directly in the ListView.ItemsPanel field. Now, I'd like to define it in the resources so that I'll be able to use it in different views, and especially in one control, the user should have the choice between Explorer view or classic list view (the default rendering for a list)

我可以定义一个ItemsPanelTemplate来正确地显示布局,直接显示在ListView中。ItemsPanel字段。现在,我想在参考资料中定义它,这样我就可以在不同的视图中使用它,特别是在一个控件中,用户可以在资源管理器视图和经典列表视图(列表的默认呈现)之间进行选择

How'd you do that? I cannot define any ItemsPanelTemplate in my ResourceDictionary, and if I define a DataTemplate it is not compatible (while I thought that following pure logic, ItemsPanelTemplate should inherit from DataTemplate, but it actually doesn't look like so).

你怎么做呢?我无法在我的ResourceDictionary中定义任何ItemsPanelTemplate,如果我定义了一个DataTemplate,它就不兼容(虽然我认为遵循纯逻辑,ItemsPanelTemplate应该继承自DataTemplate,但实际上它看起来不是这样的)。

Code snippet for the actual list:

实际列表的代码片段:



                
                    
                        
                        
                    
                

                
                    
                        
                            
                            
                                
                                
                            
                        
                    
                

            

Keeping the ItemTemplate in a static resource was easy to do, but now I can't do anything with the ItemsPanelTemplate...

在静态资源中保存ItemTemplate很容易,但是现在我不能用ItemsPanelTemplate来做任何事情…

Any ideas? I'm using MVVM so I'm trying ideally not to use code-behind if possible

什么好主意吗?我正在使用MVVM,所以如果可能的话,我尽量不使用代码隐藏

1 个解决方案

#1


7  

you would use a style for the whole ListView for that.

你可以使用整个ListView的样式。

so you would do:

所以你会做的事:


  



                        
        
            
                
                    
                    
                        
                        
                    
                
            
                    
    

if you want the user then be able to switch between explorer and classic view, just define a second Style and switch the style of the listview. This can be done for example with some VisualStates and a 'DataStateBehavior'.

如果您希望用户可以在explorer和classic视图之间切换,只需定义第二个样式并切换listview的样式。这可以通过一些可视化状态和“DataStateBehavior”来实现。

Alternatively you could create a style with some DataTriggers and Setters for the individual ItemsPanels.

或者,您也可以创建一个样式,其中有一些datatrigger和Setters用于单个ItemsPanels。


推荐阅读
author-avatar
zongnaxxl240
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有