当前位置:网站首页>win10 uwp 动态修改ListView元素布局
win10 uwp 动态修改ListView元素布局
2022-08-04 18:37:00 【林德熙】
本文告诉大家如何在代码动态修改 ListView 的元素布局,从垂直修改为水平,从水平修改为垂直
先给大家一张图看一下效果
如何需要从 cs 代码修改 ListView 的 ItemsPanel 的 ItemsPanelTemplate 从而修改元素布局是比较困难的。如修改下面代码的 Orientation 从 Horizontal 修改为 Vertical。
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>因为无法通过后台代码直接创建一个 ItemsPanelTemplate ,除了使用 XamlReader 来做。
但是这样做比较复杂。
我期望的方式是直接通过代码修改。
在堆栈网发现c# - How to set ListView ItemsStackPanel orientation by code? - Stack Overflow,里面使用 ItemsPanelRoot 来设置
if (xxListView.ItemsPanelRoot is ItemsStackPanel panel)
{
panel.Orientation = Orientation.Vertical;
}实际上的 ItemsPanelRoot 就是控制的 panel ,通过修改这个 panel 的值就可以修改列表的布局。
边栏推荐
猜你喜欢

Day018 继承

网站设计师:Nicepage 4.15 Crack By Xacker

PHP代码审计7—文件上传漏洞

Nintendo won't launch any new hardware until March 2023, report says

How does the intelligent video surveillance platform EasyCVR use the interface to export iframe addresses in batches?

当前最快的实例分割模型:YOLACT 和 YOLACT++

MySQL安装教程(详细)

EasyCVR calls the cloud recording API and returns an error and no recording file is generated. What is the reason?

The CPU suddenly soars and the system responds slowly, what is the cause?Is there any way to check?

curl命令的那些事
随机推荐
server
EasyCVR calls the cloud recording API and returns an error and no recording file is generated. What is the reason?
MMDetection 使用示例:从入门到出门
【web自动化测试】playwright安装失败怎么办
Matlab drawing 1
入选爱分析·银行数字化厂商全景报告,网易数帆助力金融数字化场景落地
mq消息积压怎么对应
防火墙基础之防火墙做出口设备安全防护
Google Earth Engine APP——一键在线查看全球1984-至今年的影像同时加载一个影像分析
22/8/4 记忆化搜索+博弈论
机器学习——线性回归
Enterprise survey correlation analysis case
ros2订阅esp32发布的电池电压数据-补充
mysql cdc 为什么需要RELOAD 这个权限?这个权限在采集数据的过程中的作用是什么?有哪
#yyds干货盘点# 面试必刷TOP101:链表相加(二)
服务器
ACP-Cloud Computing By Wakin自用笔记(2)CPU和内存虚拟化
Flask框架实现注册加密功能详解【Flask企业课学习】
测试工程师如何突破职业瓶颈?
情绪的波动起伏