I have a button on a view connected via RoutedUICommand to a command defined in ViewModel.
Outputting XAML code from a view:
<Button Content="Login" Command="{Binding Login}" />
In the CodeBehind view, I add the command binding from the ViewModel to the view binding collection:
this.CommandBindings.Add( viewModel.LoginCommandBinding );
The ViewModel model itself implements the command:
public class LoginViewModel:ViewModelBase
{
public ICommand Login { get; private set; }
public CommandBinding LoginCommandBinding { get; private set; }
public LoginViewModel( ) {
this.Login =
new RoutedUICommand( "Login", "Login", typeof( Window ) );
this.LoginCommandBinding =
new CommandBinding( Login, LoginCommandHandler, CanExecuteHandler );
}
void LoginCommandHandler( object sender, ExecutedRoutedEventArgs e ) {
}
void CanExecuteHandler( object sender, CanExecuteRoutedEventArgs e ) {
return true;
}
}
So, the command was defined with the text and the name "Input". The button itself has the contents of the "Login". Is there a way to use command text as button content?
PVitt source
share