[WPF][ListBox]鼠标拖拽多选,(Shift Key、Ctrl Key多选有效)(转)
<ListBox Name="listBox" SelectionMode="Extended">
<ListBox.Resources>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="ListBoxItem.PreviewMouseLeftButtonDown" Handler="lbItem_PreviewMouseLeftButtonDown"/>
<EventSetter Event="ListBoxItem.PreviewMouseUp" Handler="lbItem_PreviewMouseUp"/>
<EventSetter Event="ListBoxItem.PreviewMouseMove" Handler="lbItem_PreviewMouseMove"/>
</Style>
</ListBox.Resources>
<x:Type TypeName="DependencyObject"/>
<x:Type TypeName="Visual"/>
<x:Type TypeName="UIElement"/>
<x:Type TypeName="FrameworkElement"/>
<x:Type TypeName="Control"/>
</ListBox>
private bool inMouseSelectionMode = false;
private List<ListBoxItem> selectedItems = new List<ListBoxItem>();
private void lbItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// MouseDown时清空已选Item
// 同时开始"inMouseSelectionMode"
foreach (var item in selectedItems)
{
item.ClearValue(ListBoxItem.BackgroundProperty);
item.ClearValue(TextElement.ForegroundProperty);
}
selectedItems.Clear();
inMouseSelectionMode = true;
}
private void lbItem_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
// MouseUp时停止"inMouseSelectionMode"
ListBoxItem mouseUpItem = sender as ListBoxItem;
inMouseSelectionMode = false;
}
private void lbItem_PreviewMouseMove(object sender, MouseEventArgs e)
{
ListBoxItem mouseOverItem = sender as ListBoxItem;
if (mouseOverItem != null && inMouseSelectionMode && e.LeftButton == MouseButtonState.Pressed)
{
// Mouse所在的Item设置高亮
mouseOverItem.Background = SystemColors.HighlightBrush;
mouseOverItem.SetValue(TextElement.ForegroundProperty, SystemColors.HighlightTextBrush);
if (!selectedItems.Contains(mouseOverItem)) { selectedItems.Add(mouseOverItem); }
}
}
本文来自ny_dsc的博客,原文地址:http://hi.baidu.com/ny_dsc/blog/item/2bc69a31fdfb3186a8018e9a.html
[WPF][ListBox]鼠标拖拽多选,(Shift Key、Ctrl Key多选有效)(转)的更多相关文章
- 【WPF】鼠标拖拽功能DragOver和Drop
在Winform里面实现拖入功能只要设置控件AllowDrop=true; 然后实现方法 //拖入 private void txtInputPath_DragOver(object sender, ...
- WPF 在image控件用鼠标拖拽出矩形
原文:WPF 在image控件用鼠标拖拽出矩形 版权声明:博客已迁移到 http://lindexi.gitee.io 欢迎访问.如果当前博客图片看不到,请到 http://lindexi.gitee ...
- 设置zedgraph鼠标拖拽和局部放大属性(转帖)
说一下几个属性的意义和具体应用: (1)鼠标拖拽显示区域 PanModifierKeys ->> Gets or sets a value that determines which mo ...
- Java3D读取3DMax模型并实现鼠标拖拽、旋转、滚轮缩放等功能
/**-------------------------------------------------代码区--------------------------------------------- ...
- 2018-11-19-WPF-在image控件用鼠标拖拽出矩形
title author date CreateTime categories WPF 在image控件用鼠标拖拽出矩形 lindexi 2018-11-19 15:35:13 +0800 2018- ...
- CSharpGL(20)用unProject和Project实现鼠标拖拽图元
CSharpGL(20)用unProject和Project实现鼠标拖拽图元 效果图 例如,你可以把Big Dipper这个模型拽成下面这个样子. 配合旋转,还可以继续拖拽成这样. 当然,能拖拽的不只 ...
- JavaScript鼠标拖拽特效及相关问题总结
#div1{width:200px;height:200px;background:red;position:absolute;} #div2{width:200px;height:200px;bac ...
- 一款基于jQuery的支持鼠标拖拽滑动焦点图
记得之前我们分享过一款jQuery全屏广告图片焦点图,图片切换效果还不错.今天我们要分享另外一款jQuery焦点图插件,它的特点是支持鼠标拖拽滑动,所以在移动设备上使用更加方便,你只要用手指滑动屏幕即 ...
- 【狼】unity 鼠标拖拽物体实现任意角度自旋转
主要涉及函数 Input.GetAxis(“Mouse x”) 可取得鼠标横向(x轴)移动增量 Input.GetAxis(“Mouse y”) 可取得鼠标竖向(y轴)移动增量 通过勾股定理获取拖拽长 ...
随机推荐
- Entity Framework Code-First(7):Inheritance Strategy
Inheritance Strategy in Code-First: We have seen in the Code First Conventions section that it creat ...
- (转)web端测试环境的搭建(tomcat)
C/s架构,常见的QQ这种结构的程序是有服务器来提供服务的,客户端来使用服务:B/S架构不需要安装客户端,只需要浏览器就可以了例如QQ农场,BS架构的程序在更新维护的时候,不需要更新客户端,仅在服务器 ...
- Solr 6.7学习笔记(02)-- 配置文件 managed-schema (schema.xml)(1)
刚学Solr(版本6.7.0),新建一个core时,提示要求schema.xml文件,我找了半天也没在源码包中找到名为schema.xml的文件.这个版本其实用的是managed-schema文件,没 ...
- 清北刷题冲刺 11-01 p.m
轮换 #include<iostream> #include<cstdio> #include<cstring> #define maxn 1010 using n ...
- linux文件查找find
一.locate locate基于数据库索引来查找文件,数据库在开机时一段时间对更新,不会实时更新,数据库存放在(/var/lib/mlocate/mlocate.db),可以用updatedb来手动 ...
- thinkphp5.1常量定义使用
thinkphp5.1取消了系统常量 可以把常量配置在app.php文件中 //配置网站地址 'WEB_URL'=>'http://127.0.0.1/tp5', 可以使用config()函数直 ...
- python之垃圾回收机制
一.前言 Python 是一门高级语言,使用起来类似于自然语言,开发的时候自然十分方便快捷,原因是Python在背后为我们默默做了很多事情,其中一件就是垃圾回收,来解决内存管理,内存泄漏的问题. 内存 ...
- MQ 重复消费如何解决?
1. 使用幂等操作 乐观锁:每个数据有一个版本号,和当前版本号相同的时候进行更新 去重表(缓存): 唯一性索引,如果已经存在值了就不行更新 2. 算法 两个链表是否相交? 3.redis 集合相交的 ...
- js 监听浏览器刷新还是关闭事件
转载大神 http://www.cnblogs.com/gavin0517/p/5827405.html
- 注意sqlite3和java的整数数据类型的区别
作为新手的我,没有考虑数据库和java的数据类型的对应上的区别: sqlite3的数据类型和java数据类型对应上要小心,特别是整数类型. java 中int类型4位存储,范围 -2^31到2^31- ...