UWP ListView 绑定 单击 选中项 颜色
xaml
<Pagex:Class="SuperTools.Views.BlankPage3"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:interop="using:Windows.UI.Xaml.Interop"xmlns:local="using:SuperTools.Views"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"><Grid Background="Gray"><ListViewName="listView1"IsItemClickEnabled="True"ItemClick="listView1_ItemClick"><ListView.Resources><Style x:Key="ListViewItemStyle1" TargetType="ListViewItem"><!--HorizontalContentAlignment ListViewItem 整个横向填充--><Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" /><Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" /><Setter Property="Background" Value="{ThemeResource ListViewItemBackground}" /><Setter Property="Foreground" Value="{ThemeResource ListViewItemForeground}" /><Setter Property="TabNavigation" Value="Local" /><Setter Property="IsHoldingEnabled" Value="True" /><Setter Property="Padding" Value="12,0,12,0" /><Setter Property="HorizontalContentAlignment" Value="Stretch" /><Setter Property="VerticalContentAlignment" Value="Center" /><Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}" /><Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}" /><Setter Property="AllowDrop" Value="False" /><Setter Property="UseSystemFocusVisuals" Value="True" /><Setter Property="FocusVisualMargin" Value="0" /><Setter Property="FocusVisualPrimaryBrush" Value="{ThemeResource ListViewItemFocusVisualPrimaryBrush}" /><Setter Property="FocusVisualPrimaryThickness" Value="2" /><Setter Property="FocusVisualSecondaryBrush" Value="{ThemeResource ListViewItemFocusVisualSecondaryBrush}" /><Setter Property="FocusVisualSecondaryThickness" Value="1" /><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="ListViewItem"><ListViewItemPresenterHorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"CheckBoxBrush="{ThemeResource ListViewItemCheckBoxBrush}"CheckBrush="{ThemeResource ListViewItemCheckBrush}"CheckMode="{ThemeResource ListViewItemCheckMode}"ContentMargin="{TemplateBinding Padding}"ContentTransitions="{TemplateBinding ContentTransitions}"Control.IsTemplateFocusTarget="True"DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"DragBackground="{ThemeResource ListViewItemDragBackground}"DragForeground="{ThemeResource ListViewItemDragForeground}"DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"FocusBorderBrush="{ThemeResource ListViewItemFocusBorderBrush}"FocusSecondaryBorderBrush="{ThemeResource ListViewItemFocusSecondaryBorderBrush}"FocusVisualMargin="{TemplateBinding FocusVisualMargin}"FocusVisualPrimaryBrush="{TemplateBinding FocusVisualPrimaryBrush}"FocusVisualPrimaryThickness="{TemplateBinding FocusVisualPrimaryThickness}"FocusVisualSecondaryBrush="{TemplateBinding FocusVisualSecondaryBrush}"FocusVisualSecondaryThickness="{TemplateBinding FocusVisualSecondaryThickness}"PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackground}"PointerOverBackground="#FFFFAA"PointerOverForeground="{ThemeResource ListViewItemForegroundPointerOver}"PressedBackground="#FFFFAA"ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"SelectedBackground="#FFFFAA"SelectedForeground="{ThemeResource ListViewItemForegroundSelected}"SelectedPointerOverBackground="Red"SelectedPressedBackground="#FFFFAA"SelectionCheckMarkVisualEnabled="{ThemeResource ListViewItemSelectionCheckMarkVisualEnabled}" /><!--PointerOverBackground 鼠标移到元素上时;SelectedBackground 元素被选择后;SelectedPressedBackground 点击已被选择元素时;PressedBackground 点击未被选择的元素时;SelectedPointerOverBackground 鼠标移动已被选择元素上时--></ControlTemplate></Setter.Value></Setter></Style></ListView.Resources><ListView.ItemContainerStyle><StaticResource ResourceKey="ListViewItemStyle1" /></ListView.ItemContainerStyle><ItemsPanelTemplate><Grid Background="White" /></ItemsPanelTemplate><ListView.ItemTemplate><DataTemplate><GridMargin="0,0,0,0"HorizontalAlignment="Stretch"VerticalAlignment="Stretch"Background="YellowGreen"><Grid.ColumnDefinitions><ColumnDefinition Width="*" /><ColumnDefinition Width="1" /><ColumnDefinition Width="*" /><ColumnDefinition Width="1" /><ColumnDefinition Width="*" /></Grid.ColumnDefinitions><TextBlockx:Name="title_prj"Grid.Column="0"Margin="10"Text="{Binding Path=name1}" /><BorderGrid.Column="1"Width="0.5"Background="#808080" /><TextBlockx:Name="title_result"Grid.Column="2"Margin="10"Text="{Binding Path=details}" /><BorderGrid.Column="3"Width="0.5"Background="#808080" /><TextBlockx:Name="title_gray"Grid.Column="4"Margin="10"Text="{Binding Path=backgroundcolor}" /></Grid></DataTemplate></ListView.ItemTemplate></ListView></Grid> </Page>
cs
using System.Collections.ObjectModel; using Windows.UI; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media;namespace SuperTools.Views {public sealed partial class BlankPage3 : Page{ public BlankPage3(){this.InitializeComponent();var categories = new ObservableCollection<dynamic>{new {Name="name1",details="color1" ,backgroundcolor="#D90015"},new {Name="name2",details="color2" ,backgroundcolor="#DC1C17"},new {Name="name3",details="cplor3",backgroundcolor="#DE3A17" },new {Name="name3",details="color4",backgroundcolor="#E25819" }};listView1.ItemsSource = categories; }private void listView1_ItemClick(object sender, ItemClickEventArgs e){listView1.Background= new SolidColorBrush(Colors.Transparent);dynamic clickedItem = e.ClickedItem;ListViewItem item = listView1.ContainerFromItem(clickedItem) as ListViewItem;if (item != null){//item.Background = new SolidColorBrush(Colors.Red);//选中后的元素背景颜色 } }} }
转载于:https://www.cnblogs.com/lonelyxmas/p/7650259.html
UWP ListView 绑定 单击 选中项 颜色相关推荐
- css select默认选中字体颜色,通过js修改input、select默认字体颜色
textarea默认字颜色以及获取焦点后的字的颜色,焦点获取后使默认消失 输入您要输入的内容 select默认选中项颜色为灰色,选择后变为黑色(js实现) var unSelected = " ...
- ListView控件获取选中项的内容 c# 114867417
ListView控件获取选中项的内容 c# 114867417 引入控件 定义列 基本功能 整行选中 打开整行选中 true 获取选中项的数据
- Android ListView选中项居中放大(使用上下键控制,非触屏)
最近有一个功能机项目(不支持触屏)需要实现ListView选中项停在中间放大的效果,网络上的大多是用手滑动屏幕的效果,只能自己写一个. 效果实现了,但是还有小问题.实现原理主要是 1调用setSele ...
- element更改导航菜单被选中项的背景颜色
element更改导航栏被选中项的背景颜色 在使用element的导航栏菜单时,官方文档指明可以改变导航栏的的背景颜色,字体颜色以及选中项的字体颜色,但是有时我们想要使用自定义颜色.在F12中可以看见 ...
- listview改变选中行字体颜色
[android]listview改变选中行字体颜色 目标:选中item,其字体设置为#3197FF,未选中的,其字体为#FFFFFF 与listvew设置选中行item背景图片一样,使用select ...
- Qt5 QML TreeView currentIndex当前选中项的一些问题
0.前言 Qt5 QML Controls1.4 中的 TreeView 存在诸多问题,比如节点连接的虚线不好实现,currentIndex 的设置和 changed 信号的触发等.我想主要的原因在于 ...
- Android高级控件(一)——ListView绑定CheckBox实现全选,增加和删除等功能
Android高级控件(一)--ListView绑定CheckBox实现全选,增加和删除等功能 这个控件还是挺复杂的,也是项目中应该算是比较常用的了,所以写了一个小Demo来讲讲,主要是自定义adap ...
- Android ListView中CheckBox选中状态失效的最佳解决方案
Android ListView中CheckBox选中状态失效: 在ListView中某一项滑到显示区外部的时候,重新划回来时其中的CheckBox的选中状态会重置,本文提出了一种解决方案,操作起来快 ...
- 【最全IDEA个性化教程】idea设置主题+恢复主题默认设置+设置选中代码颜色+关键字颜色+设置字体大小、样式、颜色+设置背景颜色、图片+设置导航栏背景颜色+设置控制台字体样式及背景+常用快捷键)
目录 下载设置主题样式+恢复主题默认设置 1 个性化代码段 1.1设置颜色 设置光标颜色 自定义图片做背景 修改代码段的颜色和背景颜色 选中代码块颜色修改,修改括号颜色 1.2 设置字体大小.格式 1 ...
最新文章
- vue ts prop
- ibatis mysql like_关于ibatis中like用法的补充
- 百度地图API禁用点击景点弹出详细信息的方法
- java 自定义类加载器_Java-JVM 自定义类加载器
- 解密OpenShift内部通信网络
- C#开发笔记之09-如何用C#判断社会信用代码是否合法?
- 深入分析Android (build/core/*.mk脚本)
- 初识Hadoop(核心组件与应用)
- 矩阵的转置与求导运算
- oracle,pdb模式,数据库重启
- ts540服务器安装系统,ThinkServer TS540 OS安装手册 V1.3.pdf
- Android 开发日志之LBS相关开发
- 【OpenCV】- 分水岭算法
- ESP32S2片外PSRAM的使用
- Pyinstaller Pmw
- shader forge初级篇|反射材质的运用
- stm32+esp8266 通过MQTT发送到thingsboard平台
- USB OTG的工作原理
- android 生成kml,Android模拟GPS数据生成kml和nmea文件
- 百度地图线路颜色_你是铁路大亨吗?五个值得收藏的铁路地图网站
热门文章
- java求根号函数_一般实系数四次方程的一种求根公式与根的判别法则及其推导...
- python xlrd读取excel慢_python操作Excel读写--使用xlrd
- 应用密码学的笑话之MD5+Salt不安全
- Oracle出现 The Network Adapter could not establish the connection
- Oracle的数据字典常用操作(持续更新)
- 拉起支付宝个人转账填备注_支付宝转错钱给别人,我居然要回来了!
- 【kafka】kafka 消息 重放 从 一个 topic 导入 另外一个 topic
- 【Flink】Pending record count must be zero at this point : 1
- 【elasticsearch】 Regexes are disabled. Set [script.painless.regex.enabled] to [true]
- 【Elasticsearch】es IK分词器的安装