Hi guys
I have a WPF application the uses the MVVM pattern, I also have a button in my WPF client application that is binded to the ICommand implementation, How do I make the UI responsive when the command is still running?
Below is my code for my MVVM Implementation
private void processLoginRequest()
{
UserService usr = new UserService();
bool validLoginRequest;
string test = ComputerHashval(this.OperatorPassword, this.OperatorUserID);
try
{
validLoginRequest = usr.ProcessLoginRequest(this.OperatorUserID, ComputerHashval(this.OperatorPassword, this.OperatorUserID));
if (validLoginRequest == true)
{
this.MenuVisibility = true;
this.DisplayPage = new Uri("/Views/DashboardView/Dashboard.xaml", UriKind.RelativeOrAbsolute);
}
}
catch (ApplicationException ex)
{
this.ErrPanelVissible = true;
this.LoginFailedError = ex.Message;
}
}
My ICommand Implmentation
public class LoginRequest : ICommand
{
public event EventHandler CanExecuteChanged;
private MainWindowViewModel _authenViewModel;
public LoginRequest(MainWindowViewModel _viewModel)
{
this._authenViewModel = _viewModel;
this._authenViewModel.PropertyChanged += (s, e) =>
{
if (this.CanExecuteChanged != null)
{
this.CanExecuteChanged(this, new EventArgs());
}
};
}
public bool CanExecute(object parameter)
{
return this._authenViewModel.OperatorPassword != null;
}
public void Execute(object parameter)
{
this._authenViewModel.processLoginRequest();
}
}
and my XAML Page
<Button Content="Login" Height="40" Name="LogOnBtn" HorizontalAlignment="Right" Margin="0,10,10,5" Width="89" Background="#FFD0D0D0" FontWeight="Bold" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentControl}}, Path=DataContext.ProcLoginRequest, ValidatesOnExceptions=True, NotifyOnValidationError=True}"/>
Thanks