当前位置: 首页 > news >正文

刷卡登入数据获取

1.WPF刷卡登入数据获取,防止用户手动输入

//WPF输入框信息及触发命令<StackPanel Orientation="Vertical" VerticalAlignment="Center"  Margin="0 30"  Visibility="{Binding LoginMode,Converter={StaticResource loginModeWithParmVisibilityConverter}, ConverterParameter=IC卡}" ><StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="30"><TextBox hc:InfoElement.TranslateText="{Binding Path=Text,Mode=OneTime,RelativeSource={RelativeSource Mode=Self}}" Text="刷卡卡号" Margin=" 30 0 0 0" Width="101" Padding="10" VerticalAlignment="Center" IsReadOnly="True"></TextBox><TextBox Text="{Binding CardNum,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" Focusable="True" Name="t_username1" Width="170"  Padding="10" TabIndex="1"><i:Interaction.Triggers><i:EventTrigger EventName="KeyDown"><i:InvokeCommandAction Command="{Binding DataContext.KeyDownCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBox}}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBox}}}" /></i:EventTrigger><i:EventTrigger EventName="KeyUp"><i:InvokeCommandAction Command="{Binding DataContext.KeyUpCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBox}}}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBox}}}" /></i:EventTrigger></i:Interaction.Triggers></TextBox></StackPanel>

viewmodel代码

//核心命令private DateTime _lastKeyUpTime; // 上次按键弹起时间private const int KeyDownThreshold = 200; // 按键时间间隔阈值(单位:毫秒)private bool IsKeyDown = false;private DateTime KeyUpDateTime = new DateTime();public RelayCommand<object> KeyDownCommand => new RelayCommand<object>((obj) =>{System.Windows.Controls.TextBox textBox = obj as System.Windows.Controls.TextBox;if (IsKeyDown && ((LoginMode)GlobalData.LoginMode) == LoginMode.IC卡 && textBox.Text.Length > 1)//加一个是否是密码输入的判断{textBox.Clear();return;}if (Keyboard.IsKeyDown(Key.Enter)) // 判断是否是 Enter 键{LoginCmd.Execute(null);return;}IsKeyDown = true;//KeyUpDateTime = DateTime.Now;});public RelayCommand<object> KeyUpCommand => new RelayCommand<object>((obj) =>{System.Windows.Controls.TextBox textBox = obj as System.Windows.Controls.TextBox;//var temp = DateTime.Now;判断是否密码输入,密码输入直接return。//if (((LoginMode)GlobalData.LoginMode) == LoginMode.IC卡 && (temp - KeyUpDateTime).TotalMilliseconds > 100  && textBox.Text.Length > 1)//{//    textBox.Clear();//}var currentTime = DateTime.Now;// 计算按键时间间隔var interval = (currentTime - _lastKeyUpTime).TotalMilliseconds;// 如果按键间隔大于阈值,清除输入内容if (textBox.Text.Length > 1 && interval > KeyDownThreshold){textBox.Clear();return;}_lastKeyUpTime = currentTime; // 更新按键时间IsKeyDown = false;});
http://www.dtcms.com/a/265684.html

相关文章:

  • 【ArcGISPro】基于Pro的Python环境进行Django简单开发Web
  • 两个PHY芯片之间,是如何连接进行通信的?
  • 并行科技MaaS平台支持文心4.5系列开源模型调用
  • MySQL主从延迟深度解析:现象、原因与实战解决方案
  • KMP(Kotlin Multiplatform)改造(Android/iOS)老项目
  • 舵轮时钟-STM32-28路PWM--ESP8266-NTP时间
  • Babylon.js 材质克隆与纹理共享:你可能遇到的问题及解决方案
  • 从UI设计到数字孪生实战演练:构建智慧城市的智慧停车系统
  • 大势智慧亮相第十八届中国智慧城市大会
  • 暑期出游,解锁“智慧”新玩法!
  • 浏览器原生控件上传PDF导致hash值不同
  • 使用HAProxy搭建Web群集:原理、步骤与实战总结
  • AlpineLinux安装RabbitMQ及其管理界面
  • 攻防世界0-MISC-隐藏的信息
  • VS Code 的 Copilot Chat 扩展程序
  • AI学习笔记三十:基于yolov8的web显示
  • 在 VSCode 中高效配置自定义注释模板 (无需插件)
  • 在小程序中实现实时聊天:WebSocket最佳实践
  • Tarjan 算法的两种用法
  • 支持向量机(SVM)分类
  • JavaScript的现代进阶:从ES6到ES15
  • 机器学习-03(机器学习任务攻略)
  • npm 命令入门指南(前端小白版)
  • 使用numpy的快速傅里叶变换的一些问题
  • 记忆翻牌记忆力小游戏流量主微信小程序开源
  • 万能公式基分析重构补丁复分析和欧拉公式原理推导
  • 国外开源集成平台(业务编排)camel及Mule介绍
  • 为什么是直接在**原型(prototype)上**添加函数
  • 构建引擎: 打造小程序编译器
  • 边缘计算解决方案:电力作业行为图像识别