当前位置: 首页 > 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.lryc.cn/news/579581.html

相关文章:

  • 纯前端批量下载
  • CPT204-Advanced OO Programming: Sorting排序
  • 扣子空间PPT生产力升级:AI智能生成与多模态创作新时代
  • JS模块导出导入笔记 —— 默认导出 具名导出
  • 行波进位加法器 (Carry-Propagate Adder)
  • UE5 瞄准偏移(AimOffset)功能详解
  • 独立开发者软件出海:如何用Semrush高效洞察与增长
  • RJ45 连接器(水晶头)的引脚定义
  • 贪心专题练习
  • 强实时运动控制内核MotionRT750(一):驱动安装、内核配置与使用
  • 马斯克脑机接口(Neuralink)技术进展,已经实现瘫痪患者通过BCI控制电脑、玩视频游戏、学习编程,未来盲人也能恢复视力了
  • OpenEuler 24.03 用 Ansible 一键完成 SSH 互信 —— 从踩坑到最终方案
  • 站在 Java 程序员的角度如何学习和使用 AI?从 MVC 到智能体,范式变了!
  • 渗透测试中 phpinfo() 的信息利用分析
  • Part 0:射影几何,变换与估计-第三章:3D射影几何与变换
  • 工作中用到过哪些设计模式?是怎么实现的?
  • Robot---能打羽毛球的机器人
  • Linux操作系统之文件(二):重定向
  • 物联网MQTT协议与实践:从零到精通的硬核指南
  • 【王阳明代数】基于Perplexica二次开发的道装资源标识符与重定向知识路由系统
  • 使用HAProxy搭建Web群集:原理、步骤与实战总结
  • Node.js特训专栏-实战进阶:12. 数据库事务处理与并发控制
  • 基于 alpine 构建 .net 的基础镜像
  • 基于MATLAB的风力发电机无人机巡检路径优化研究
  • 利用人名语言分类案例演示RNN、LSTM和GRU的区别(基于PyTorch)
  • Go调度器的抢占机制:从协作式到异步抢占的演进之路|Go语言进阶(7)
  • Android Profiler 丢帧分析教程及案例
  • WPF学习笔记(22)项面板模板ltemsPanelTemplate与三种模板总结
  • 【Git】同时在本地使用多个github账号进行github仓库管理
  • 两级缓存 Caffeine + Redis 架构:原理、实现与实践