WPF command and exception in ViewModel

Button

has a binding Commandin ViewModel(it runs some method Savein the ViewModel). The method Savemay fail and throw an exception.

What is the best practice on how to catch these exceptions? It would be enough to show MessageBox, but I do not want to do it in ViewModel(it is not).

+5
source share
2 answers

1 - I do not believe that this is "not the right way."

Exception, ViewModel, ViewModel. , MessageBox, " ". , MVVM - , -, UI- -. - - ViewModel

2 - , ( MVVM - heh -), :

  • ( Binding.ValidationRules? if not, ), , Exception
  • , Exception, .. try-catch, - catch, , UI ( , , Trigger , )

, , , " MVVM", (, )... , , . , , MVVM , , , (, , AttachedBehaviors DoubleClick. EventHandler, DoubleClick MVVM DoubleClick. 1 100 + XAML , . , )

!

+6

, ? unit test viewmodel? , IMessageBoxService, vm.

, . , .

+6

All Articles