社区
其他技术讨论专区
帖子详情
如何在后台切换ListView的ItemsPanelTemplate?通过后台的代码将StackPanel与Warpanel相互切换
weixin_38062043
2016-12-28 03:17:30
想在后台通过事件代码中切换ListView的显示风格ItemsPanelTemplate,当事件触发时,StackPanel与Warpanel相互切换,如何做到?
...全文
37
1
打赏
收藏
如何在后台切换ListView的ItemsPanelTemplate?通过后台的代码将StackPanel与Warpanel相互切换
想在后台通过事件代码中切换ListView的显示风格ItemsPanelTemplate,当事件触发时,StackPanel与Warpanel相互切换,如何做到?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
weixin_38068389
2016-12-28
打赏
举报
回复
Hi 轮回的齿轮,
你可以使用SetValue来重新设置Style的属性值,这样就可以在后台代码中进行动态切换。
ListView.SetValue(ListView.StyleProperty, this.Resources["Style1"]); ListView.SetValue(ListView.StyleProperty, this.Resources["Style2"]);
这些Style是你在窗体资源中为Listview进行定义的,比如下面代码:
<Style x:Key="Style1" x:Name="a" TargetType="{x:Type ListView}" > <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <StackPanel Orientation="Vertical"> </StackPanel> </ItemsPanelTemplate> </Setter.Value> </Setter> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate> <StackPanel Margin="10 20 0 0" > <Label MaxWidth="112" Margin="0,10,0,0" > <TextBlock TextWrapping="Wrap" TextAlignment="Center" FontSize="12" FontWeight="Bold" Text="{Binding Name}" Height="27" Width="105"></TextBlock> </Label> </StackPanel> </DataTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="Style2" x:Name="a2" TargetType="{x:Type ListView}" > </Style>
WPF_
ListView
横向显示.zip
ListView
横向显示,比用string去便利更方便,有需要的可以用一用,研究了很久才搞成的效果,可以继续优化,
使用IComparer对WPF
ListView
进行排序的更通用的方法
一种使用通用方法对WPF
ListView
进行排序的简单方法。
WPF
Items
Panel
Template
的详细使用教程
WPF 中的
Items
Panel
Template
主要用于自定义
Items
Control 控件(如 ListBox、
ListView
、ComboBox)的布局行为。它定义了如何排列
Items
Control 的子元素。在默认情况下,大多数
Items
Control 使用
Stack
Panel
垂直排列子项,但通过
Items
Panel
Template
可以实现更加灵活的布局。
wpf
listview
images
<
ListView
x:Name="lv"> <
ListView
.
Items
Panel
> <
Items
Panel
Template
> <
Stack
Panel
Orientation="Vertical"/> </
Items
Panel
Template
> </
ListView
.
Items
Panel
> <
ListView
.Item
Template
> <Data
Template
> <
Stack
Panel
&...
WPF案例 (六) 动态
切换
UI布局
这个Wpf示例对同一个界面支持以
ListView
或者CardView的布局方式呈现界面,使用控件
Items
Control绑定数据源,使用Data
Template
为
Items
Control分别预定义了
ListView
和CardView的样式,在程序运行时,可在这两种Layout之间互相
切换
,界面如下。源
代码
在这里下载 为
Items
Control定义
ListView
UI布局的Item...
其他技术讨论专区
476
社区成员
790,963
社区内容
发帖
与我相关
我的任务
其他技术讨论专区
其他技术讨论专区
复制链接
扫一扫
分享
社区描述
其他技术讨论专区
其他
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章