[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轴)移动增量 通过勾股定理获取拖拽长 ...
随机推荐
- 2、linux-compress and uncompresse
1.单个文件 压缩 解压 gzip file1 gzip -d file1.gz或者gunzip file1.gz #file1文件即会被压缩为 file1.gz,file1原文件删除:解压后同样删 ...
- vs2013提交项目到github
提交项目之前必须先安装Git,下载地址:https://git-scm.com/download/win 1.登录Github后,在顶部导航栏选择New repository: 2.打开Create ...
- uva 10817(数位dp)
uva 10817(数位dp) 某校有m个教师和n个求职者,需讲授s个课程(1<=s<=8, 1<=m<=20, 1<=n<=100).已知每人的工资c(10000 ...
- uva 1614奇怪的股市(归纳法证明,贪心)
uva 1614奇怪的股市(归纳法证明,贪心) 输入一个长度为n的序列a,满足\(1\le a_i\le i\),要求确定每个数的正负号,使得所有数的总和为0.例如a={1, 2, 3, 4},则4个 ...
- [转]SAP一句话入门SD模块
SD是Sales and Distribution的简称.在SAP系统中,销售与分销模块处在供应链下游,关注从客户订单到向客户收款的全过程. SD模块中的Sales好理解,而Distribution却 ...
- 「模拟赛20180306」回忆树 memory LCA+KMP+AC自动机+树状数组
题目描述 回忆树是一棵树,树边上有小写字母. 一次回忆是这样的:你想起过往,触及心底--唔,不对,我们要说题目. 这题中我们认为回忆是这样的:给定 \(2\) 个点 \(u,v\) (\(u\) 可能 ...
- elasticsearch常用工具及使用
1. 数据库工具:https://github.com/jprante/elasticsearch-jdbc 2.数据展示:https://github.com/mobz/elasticsearch- ...
- PHP 获取acm近期比赛
<?php // author: Moore Jiang. ini_set('display_errors',1); //错误信息 ini_set('display_startup_errors ...
- js中大数据量form表单卡顿问题解决
转载大神: http://www.mamicode.com/info-detail-1773696.html
- LeetCode 225 Implement Stack using Queues 用队列实现栈
1.两个队列实现,始终保持一个队列为空即可 class MyStack { public: /** Initialize your data structure here. */ MyStack() ...