2016-09-19 68 views
0

我有這個Passwordbox這個觸發器:WPF Relaycommand得到passwordbox值

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

我如何,我RelayCommand,讓我PasswordBox的內容?

這是我的繼電器命令:

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

private void GoPasswordChanged() 
{  
} 
+0

剛剛訪問'PasswordBox.Password'財產? – Noctis

+0

http://stackoverflow.com/a/4649830/2819451 – Gopichandar

+0

Nop,我的繼電器命令是在我的viewmodel中,我無法直接訪問Passworxbox.password – WWWWWWWWWWWWWWP

回答

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; 
     } 
+0

恕我直言,請將您的密碼作爲視圖模型中的屬性綁定。所以你可以直接從viewmodel進行訪問 – Eldho