CaptureUnCaptureMouse捕获鼠标

关注点:
1、 获取 捕获鼠标按钮的名字 的显示

  1. 两种方法:一是直接获取GotMouseCapture路由事件中确定事件引发者e.source的名字
  2. 二是新建一个IInputElement,获取鼠标捕获的元素Mouse.Captured;得到按钮的引用即可
// GotMouseCapture event handler
// MouseEventArgs.source is the element that has mouse capture
private void ButtonGotMouseCapture(object sender, MouseEventArgs e)
{var source = e.Source as Button;if (source != null){// Update the Label that displays the sample results.lblHasMouseCapture.Content = source.Name;}// Another way to get the element with Mouse Capture// is to use the static Mouse.Captured property.else{// Mouse.Capture returns an IInputElement.IInputElement captureElement;captureElement = Mouse.Captured;// Update the Label that displays the element with mouse capture.lblHasMouseCapture.Content = captureElement.ToString();}
}

2、 点击Capture Mouse按钮时,使RaidoButton指示的鼠标 执行 被鼠标捕获状态。此时鼠标变大??就像鼠标放于按钮上状态。。。答:根据按钮上鼠标捕获定义,意味着捕获鼠标就是默认鼠标在按钮上拖移状态。

private void OnCaptureMouseRequest(object sender, RoutedEventArgs e)
{Mouse.Capture(_elementToCapture);
}private IInputElement _elementToCapture;private void OnRadioButtonSelected(object sender, RoutedEventArgs e)
{var source = e.Source as RadioButton;if (source != null){switch (source.Content.ToString()){case "1":_elementToCapture = Button1;break;case "2":_elementToCapture = Button2;break;case "3":_elementToCapture = Button3;break;case "4":_elementToCapture = Button4;break;}}
}

CommandSourceControlUsingSystemTime使用系统时间做比较值的命令源控件

1、实现效果

  1. 滑块的滚动、点击的增减值设置
  2. 同步显示当前时间秒数
  3. 执行命令绑定方法,及判断命令查询状态

2、关键词

  1. CommandBinding
  2. Slider.DecreaseSmall.Execute
  3. Timer.Elasped

3、静态组织
window的命令绑定设置:

  1. Command绑定到window的一个静态自定义路由命令
  2. 命令附加执行方法Executed,自定义方法附加到此句柄
  3. 命令能否执行CanExecute,附加判断方法,返回bool
<!-- Command Binding for the Custom Command -->
<Window.CommandBindings><CommandBinding Command="{x:Static local:MainWindow.CustomCommand}"Executed="CustomCommandExecuted"CanExecute="CustomCommandCanExecute" />
</Window.CommandBindings>

完整滑块状态设置:

<Border BorderBrush="DarkBlue"BorderThickness="1"Height="75"Width="425"><StackPanel Orientation="Horizontal"><Button Command="Slider.DecreaseSmall"CommandTarget="{Binding ElementName=secondSlider}"Height="25"Width="25"Content="-"/><Label VerticalAlignment="Center">0</Label><Slider Name="secondSlider"Minimum="0"Maximum="60"Value="15"TickFrequency="5"Height="50"Width="275" TickPlacement="BottomRight"LargeChange="5"SmallChange="5" AutoToolTipPlacement="BottomRight" AutoToolTipPrecision="0"MouseWheel="OnSliderMouseWheel"MouseUp="OnSliderMouseUp" /><Label VerticalAlignment="Center">60</Label><Button Command="Slider.IncreaseSmall"CommandTarget="{Binding ElementName=secondSlider}"Height="25"Width="25"Content="+"/></StackPanel>
</Border>

4、动态流程
设置计时器:显示随时间秒数更新的时间数字

  1. 新建计时器类Timer,引发时间间隔事件Elapsed
  2. 设置时间间隔及激活计时器
  3. 线程调度执行同步委托
  4. Label显示现在时间秒数,同时强制更新注册命令状态
// System Timer setup.
var timer = new Timer();
timer.Elapsed += timer_Elapsed;
timer.Interval = 1000;
timer.Enabled = true;// System.Timers.Timer.Elapsed handler
// Places the delegate onto the UI Thread's Dispatcher
private void timer_Elapsed(object sender, ElapsedEventArgs e)
{// Place delegate on the Dispatcher.Dispatcher.Invoke(DispatcherPriority.Normal,new TimerDispatcherDelegate(TimerWorkItem));
}// Method to place onto the UI thread's dispatcher.
// Updates the current second display and calls
// InvalidateRequerySuggested on the CommandManager to force the
// Command to raise the CanExecuteChanged event.
private void TimerWorkItem()
{// Update current second display.lblSeconds.Content = DateTime.Now.Second;// Forcing the CommandManager to raie the RequerySuggested event.CommandManager.InvalidateRequerySuggested();
}

判断命令能否执行:

// CanExecute Event Handler.
//
// True if the current seconds are greater than the target value that is
// set on the Slider, which is defined in the XMAL file.
private void CustomCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{if (secondSlider != null){e.CanExecute = DateTime.Now.Second > secondSlider.Value;}else{e.CanExecute = false;}
}

滑块中轮滚动事件,引起滑块值增减固定值

  1. 获取滑块引用
  2. 判断滚动方向值,增减滑块值Slider.DecreaseSmall.Execute
private void OnSliderMouseWheel(object sender, MouseWheelEventArgs e)
{var source = e.Source as Slider;if (source != null){if (e.Delta > 0){// Execute the Slider DecreaseSmall RoutedCommand.// The slider.value propety is passed as the command parameter.Slider.DecreaseSmall.Execute(source.Value, source);}else{// Execute the Slider IncreaseSmall RoutedCommand.// The slider.value propety is passed as the command parameter.Slider.IncreaseSmall.Execute(source.Value, source);}}
}

ps:此示例的e.Prameter为空,不显示秒数。

WPF:Input and Commands输入和命令(1)相关推荐

  1. linux read函数_Linux中shell输入ls命令后会系统会发生什么

    大家都用过Shell执行一些Linux命令 在命令的背后,到底发生了什么呢,让我们来一起探索 Shell执行主流程 1.Printthe info of reminding 打印提示信息 2.Wait ...

  2. Linux shell 学习笔记(10)— 处理用户输入(命令行读取参数、读取用户输入、超时处理)

    1. 命令行参数 向 shell 脚本传递数据的最基本方法是使用命令行参数.命令行参数允许在运行脚本时向命令行添加数据. $ ./addem 10 30 本例向脚本 addem 传递了两个命令行参数( ...

  3. 了解 WPF 中的路由事件和命令

    目录 路由事件概述 WPF 元素树 事件路由 路由事件和组合 附加事件 路由命令概述 操作中的路由命令 命令路由 定义命令 命令插入 路由命令的局限 避免命令出错 超越路由命令 路由处理程序示例 要想 ...

  4. python信息传送管道_python – 获取返回管道输入的命令

    我有这个 Python 3代码存储在pipe.py中,它接受一些管道输入并逐行打印: import sys for i, line in enumerate(sys.stdin): print(&qu ...

  5. HTML里怎么设置密码框为星号,input密码框输入后设置显示为星号或其他样式

    预览效果 核心代码 {{"*".repeat(text.length)}} :type="type=='number'?'tel':'text'" ref=&q ...

  6. 关于微信手机端IOS系统中input输入框无法输入的问题

    最近两天做移动端游戏举报页面.遇到一个问题,移动端的input都不能输入了,后来发现可能是 -webkit-user-select :none ; 在移动端开发中,我们有时有针对性的写一些特殊的重置, ...

  7. 在不同浏览器中,input里面的输入光标大小表现形式却大不相同

    问题:在不同浏览器中,input里面的输入光标大小表现形式却大不相同,具体的如下: IE:不管该行有没有文字,光标高度与font-size一致. FF:该行有文字时,光标高度与font-size一致. ...

  8. 开始→运行→输入的命令集锦(转载)

    开始→运行→输入的命令集锦 mstsc--远程桌面连接 logoff--注销命令 rononce -p --15秒关机 tsshutdn--60秒倒计时关机命令 iexpress--木马捆绑工具,系统 ...

  9. adb 输入回车命令_adb adb shell 相关命令

    在Mac上配置adb命令 在Mac OS中使用adb命令时,应进行变量配置,步骤如下: 一.终端中输入 cd ~ 二.输入touch .bash_profile 回车 touch:如果没有,则创建文件 ...

最新文章

  1. Gridview改变单元格颜色
  2. mysql5.5安装
  3. 长此以往的发展,以BCH为代表的数字货币终将会为自己正名
  4. java == equals_java中==与equals
  5. Django 使用 HttpResponse 返回 json 字符串显示 Unicode 编码
  6. win 7 系统ie浏览器升级11版本后,f12功能不可用的问题
  7. lucene学习的小结
  8. 35岁学python爬虫_35岁码农的机器学习入门之路-python篇
  9. C# Quartz.Net 定时任务的简单使用
  10. 不要有思维的惯性, 做每件事情之前, 都【确认好要做什么】!
  11. 删除mysql数据库_安装/删除MySQL数据库
  12. 拓端tecdat|R语言可视化渐近正态性、收敛性:大数定律、中心极限定理、经验累积分布函数
  13. 是时候该了解下Unity3D了
  14. 武汉ISO27001认证的完整步骤
  15. dtft变换的性质_dtft(dtft和dft的关系区别)
  16. 对话斯坦福商学院教授:颠覆大公司的不是技术,是商业模式
  17. Php 骰子游戏,寄娱于学第2天——PHP骰子游戏篇--优化
  18. 中科大计算机电子信息,中国科学技术大学电子工程与信息科学系
  19. 游戏辅助 -- 走路call中ecx值分析
  20. 面向对象程序设计php,php面向对象的程序设计

热门文章

  1. AI同传效果媲美人类,百度翻译出品全球首个上下文感知机器同传模型
  2. 细思极恐!只需54块钱,你也能让AI伪造一系列联合国发言
  3. docker-ce 配置初始化后服务启动报错
  4. ionic app调试问题
  5. QQ圈子:从哪里来,到哪里去
  6. POI按照源单元格设置目标单元格格式
  7. LR学习笔记三 之 界面分析
  8. 网络安全 — 安全架构
  9. Linux 操作系统原理 — 文件系统 — 虚拟文件系统
  10. Python基本语法_集合set/frozenset_内建方法详解