如何绑定PasswordBox控制中的Password属性
2015-11-08 18:19
459 查看
网上有同学分享了通过中间Buffer绑定Passwordbox的password属性,感觉有点麻烦。发现一简单方法拿出来和大家分享。。
步骤1:
在引用 中增加 :
System.Windows.Interactivity
步骤2:
在xaml中增加:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
<PasswordBox x:Name="passwordBox" HorizontalAlignment="Left" Height="43" Margin="365,10,0,0" VerticalAlignment="Top" Width="374"> <i:Interaction.Triggers> <span style="white-space:pre"> </span><i:EventTrigger EventName="PasswordChanged"> <span style="white-space:pre"> </span><i:InvokeCommandAction Command="{Binding PasswordChanged}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type PasswordBox}}}"/> <span style="white-space:pre"> </span></i:EventTrigger> </i:Interaction.Triggers> </PasswordBox>
在ViewModel中增加:
private string pwd; public string PWD { get { return pwd; } set { pwd = value; this.RaisePropertyChanged("pwd"); } }
public ICommand PasswordChanged { get { return new DelegateCommand<PasswordBox>((pb) => { if(pb != null) { PWD = pb.Password; } }); } }
OK了,试试看吧!
相关文章推荐
- PHP 7的一些引人注目的新特性简单介绍
- Springloaded使用
- Android基础入门教程——9.2 MediaPlayer播放音频与视频
- select into from 和 insert into select 的用法和区别
- 01分数规划
- JAVA的内省机制(introspector)与反射机制(reflection)
- 汇编语言-内中断
- [Machine Learning]4.逻辑回归(logistic regression)
- 学习SASS
- Mybatis 源码分析--crud
- 汇编语言-内中断
- 使用shell脚本搭建源码LAMP环境
- 复习线段树
- Mac上远程桌面连接Windows Server 2012 R2
- opencv中结构体分析
- 星空
- Linux忘记 root密码的解决办法
- mysql之lvm快照方式备份恢复
- mysql备份还原数据库
- UIFont中fontName大全