Youness Benbiga Youness Benbiga - 1 year ago 210
C# Question

Validation MVVM WPF

I already set validation in all my output that works fine but I have a lot of view and a next button, I want that button to be disabled every time there is an error in the output, it's already set on IsValid and I did this in the code behind of the view:

private void abc_Click(object sender, RoutedEventArgs e)
if (Validation.GetHasError(CinInput) == true|| .......)

I need a solution to bind the the result to my viewmodel so i can set isvalid to false any suggestion?

Answer Source

If you're using data binding then its possible to pass a command or command parameter to the viewmodel. Looks like you're not following MVVM pattern from your abc_click.

You can access your viewmodel like this from your code behind :

var viewModel = DataContext as ViewModelClassName;
viewModel.SomeBooleanProperty = true; // Or false
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download