WPF Relaycommand获取密码箱值

时间:2016-09-19 09:52:24

标签: wpf mvvm

我有这个触发器的密码箱:

eval('var '+name+'=function(){alert("hello");};');

如何在我的RelayCommand中获取PasswordBox的内容?

这是我的接力命令:

<PasswordBox>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="PasswordChanged">
            <i:InvokeCommandAction Command="{Binding PasswordChanged}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</PasswordBox>

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,我只想改变:

<i:InvokeCommandAction Command="{Binding PasswordChanged}" />

致:

 <i:InvokeCommandAction Command="{Binding PasswordChanged}" CommandParameter="{Binding ElementName=PasswordBoxInput}" />

并且:

PasswordChanged = new RelayCommand<object>(param => this.GoPasswordChanged(param));

private void GoPasswordChanged(param)
        {

        }

致:

private void GoPasswordChanged(object param)
        {
            var passwordBox = param as PasswordBox;
            var password = passwordBox.Password;
        }