2018-8-10-win10-UWP-ListView-
| title | author | date | CreateTime | categories |
|---|---|---|---|---|
|
win10 UWP ListView
|
lindexi
|
2018-08-10 19:16:53 +0800
|
2018-2-13 17:23:3 +0800
|
Win10 UWP
|
横向布局
默认 ListView 是垂直,那么如何让 ListView 水平?
可以使用下面代码
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
设置代码可以进行横向。
如果发现 UWP ListView 横向没有滚动条,可以使用 ScrollViewer 添加
<ListView ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.VerticalScrollMode="Disabled">
使用从左到右放元素
实际上 ItemsPanelTemplate 可以放很多个类型,如 WrapGrid 和 ItemsWrapGrid ,下面我告诉大家如何做出这个效果
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal"></ItemsWrapGrid>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
这时可以设置元素的宽度,或者高度,这样可以做出下面的效果。
选中显示元素
有一些元素是要 Item 选中显示,不选中不显示
如何绑定到Item 的状态,是否被选中?
如果可以写在后台代码多的话,一个简单的方法是在SelectionChanged直接让 AddItems 的显示,其他不显示。
如何想要定义样式,可以参见:https://msdn.microsoft.com/en-us/library/windows/apps/mt299136.aspx
首先把代码复制下来,然后修改 Selected 的动画,添加自己元素在ControlTemplate,看起来就是
<ControlTemplate TargetType="ListViewItem">
<Grid>
<ContentPresenter ></ContentPresenter>
<Button x:Name="b" Opacity="0" HorizontalAlignment="Center" Content="显示"></Button>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<!--<VisualState x:Name="Unselecting">
<Storyboard BeginTime="0:0:0">
<DoubleAnimation Storyboard.TargetName="b"
Storyboard.TargetProperty="Opacity"
Duration="0:0:0.1"
To="0" />
</Storyboard>
</VisualState>-->
<VisualState x:Name="Unselected">
<Storyboard BeginTime="0:0:0">
<DoubleAnimation Storyboard.TargetName="b"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="0" />
</Storyboard>
</VisualState>
<VisualState x:Name="Selected">
<Storyboard BeginTime="0:0:0">
<DoubleAnimation Storyboard.TargetName="b"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
上面代码的元素 b 就是加上去的元素,参见他的做法,可以看到这个方法可以在 选择时显示,但是我无法在不选择时隐藏,原因没找到。
根据上面代码,可以做很小修改,在选择改变时,手动使用变化。
首先把 Selected 改为 CustomSelected 现在的代码换为
<ControlTemplate TargetType="ListViewItem">
<Grid>
<ContentPresenter ></ContentPresenter>
<Button x:Name="b" Opacity="0" HorizontalAlignment="Center" Content="显示"></Button>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<!--<VisualState x:Name="Unselecting">
<Storyboard BeginTime="0:0:0">
<DoubleAnimation Storyboard.TargetName="b"
Storyboard.TargetProperty="Opacity"
Duration="0:0:0.1"
To="0" />
</Storyboard>
</VisualState>-->
<VisualState x:Name="CustomUnselected">
<Storyboard BeginTime="0:0:0">
<DoubleAnimation Storyboard.TargetName="b"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="0" />
</Storyboard>
</VisualState>
<VisualState x:Name="CustomSelected">
<Storyboard BeginTime="0:0:0">
<DoubleAnimation Storyboard.TargetName="b"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
在列表的选择改变时,需要在后台代码写
var listView = (sender as ListView);
if (listView == null)
{
return;
}
if (e.AddedItems != null)
{
foreach (var item in e.AddedItems)
{
Debug.WriteLine(item);
ListViewItem litem = listView.ContainerFromItem(item) as ListViewItem;
if (litem != null)
{
VisualStateManager.GoToState(litem, "CustomSelected", true);
}
}
}
if (e.RemovedItems != null)
{
foreach (var item in e.RemovedItems)
{
Debug.WriteLine(item);
ListViewItem litem = listView.ContainerFromItem(item) as ListViewItem;
if (litem != null)
{
VisualStateManager.GoToState(litem, "CustomUnselected", true);
}
}
}
这个方法是比较差的,但是可以使用
参见:http://stackoverflow.com/questions/43461819/the-listviewitem-style-cant-trigger-unselected
ListViewItem 默认
<Style
TargetType="ListViewItem">
</Style>
WPF ListView 宽度
使用下面的代码可以让 WPF 的 ListView 的 Item 宽度和他一样
HorizontalContentAlignment="Stretch"
或
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
2018-8-10-win10-UWP-ListView-的更多相关文章
- win10 uwp 列表模板选择器
本文主要讲ListView等列表可以根据内容不同,使用不同模板的列表模板选择器,DataTemplateSelector. 如果在 UWP 需要定义某些列的显示和其他列不同,或者某些行的显示和其他行不 ...
- win10 uwp 商业游戏 1.1.5
本文是在win10 uwp 商业游戏 基础上继续开发,添加一些无聊的游戏 因为在发布几个月,下载量很少,小伙伴说游戏就玩不到几分钟就不想玩,于是我就想加入其他游戏 下面我来告诉大家如何在游戏中添加多个 ...
- win10 uwp 毛玻璃
毛玻璃在UWP很简单,不会和WPF那样伤性能. 本文告诉大家,如何在 UWP 使用 win2d 做毛玻璃. 毛玻璃可以使用 win2D 方法,也可以使用 Compositor . 使用 win2d 得 ...
- win10 uwp 商业游戏 1.2.1
上一个游戏已经告诉大家如何写多个游戏,现在继续写这个无聊的游戏 希望大家在看这篇文章之前先看win10 uwp 商业游戏,在这个文章告诉了大家如何创建游戏. 修改数值 可以从上一篇的博客的游戏看到升级 ...
- win10 uwp 商业游戏
本文告诉大家去做一个商业游戏,游戏很简单,几乎没有什么技术 游戏的开始,需要添加框架库,于是引用我自己写的库. 首先是创建一个启动页面,这个页面是显示启动的. 在显示启动的时候,是需要加载游戏需要使用 ...
- win10 uwp 手把手教你使用 asp dotnet core 做 cs 程序
本文是一个非常简单的博客,让大家知道如何使用 asp dot net core 做后台,使用 UWP 或 WPF 等做前台. 本文因为没有什么业务,也不想做管理系统,所以看到起来是很简单. Visua ...
- win10 uwp 使用 Microsoft.Graph 发送邮件
在 2018 年 10 月 13 号参加了 张队长 的 Office 365 训练营 学习如何开发 Office 365 插件和 OAuth 2.0 开发,于是我就使用 UWP 尝试使用 Micros ...
- Win10 UWP开发系列:实现Master/Detail布局
在开发XX新闻的过程中,UI部分使用了Master/Detail(大纲/细节)布局样式.Win10系统中的邮件App就是这种样式,左侧一个列表,右侧是详情页面.关于这种 样式的说明可参看MSDN文档: ...
- Win10 UWP开发实现Bing翻译
微软在WP上的发展从原来的Win7到Win8,Win8.1,到现在的Win10 UWP,什么是UWP,UWP即Windows 10 中的Universal Windows Platform简称.即Wi ...
- Win10/UWP开发—使用Cortana语音与App后台Service交互
上篇文章中我们介绍了使用Cortana调用前台App,不熟悉的移步到:Win10/UWP开发—使用Cortana语音指令与App的前台交互,这篇我们讲讲如何使用Cortana调用App的后台任务,相比 ...
随机推荐
- bzoj2582 [Usaco2012Jan]Bovine Alliance
[Usaco2012Jan]Bovine Alliance Time Limit: 2 Sec Memory Limit: 128 MB Description Bessie and her bovi ...
- Nuget--基础连接已经关闭
1.Nuget---基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系 修改一下 Package Source 改为 http://packages.nuget.org 2.Nuget- ...
- openface人脸识别框架
openface的githup文档地址:http://cmusatyalab.github.io/openface/ openface的安装: 官方推荐用docker来安装openface,这样方便快 ...
- 企业微信上传 带中文名称的 临时素材资源 报错 44001:empty media data
错误原因:urllib3的老版本bug,卸载掉 requests,urllib3,从新安装最新版的requests(此包内部依赖urllib3): 我从新安装的是 requests==2.22.0 及 ...
- IDA技巧
3. 用[shift+F12]调出字符串表,再根据这些字符串,查看引用的地方,也可以分析出一些sub_0XXXX函数的功能. 进入import函数内 x查看调用处 jump to xref 跳到引用 ...
- Spring 讲解(五)
Spring 中使用 xml 配置开发和使用注解开发案例 1.Spring 中使用 xml 配置开发案例 接口 public interface UserDao { void add(User use ...
- Vue学习笔记【32】——Vue路由(watch、computed和methods之间的对比)
computed属性的结果会被缓存,除非依赖的响应式属性变化才会重新计算.主要当作属性来使用: methods方法表示一个具体的操作,主要书写业务逻辑: watch一个对象,键是需要观察的表达式,值是 ...
- layout -panel01
<script src="~/jquery-easyui-1.5.5.2/jquery.min.js"></script> <link href=&q ...
- SQL Join连接
SQL 连接(Joins) SQL join 用于把来自两个或多个表的行结合起来. SQL JOIN SQL JOIN 子句用于把来自两个或多个表的行结合起来,基于这些表之间的共同字段. 最常见的 J ...
- PHP disk_total_space() 函数
定义和用法 disk_total_space() 函数返回指定目录的磁盘总容量,以字节为单位. 语法 disk_total_space(directory) 参数 描述 directory 必需.规定 ...