Why is it not recommended to use the C# project event with WPF and MVVM?

Asked

Viewed 132 times

2

I am too young for WPF I am doing a project using MVVM and Entity Framework and it has been suggested not to have any event Click to a button in the code behind a window, for what reason? What is the alternative to replace the below event without breaking the suggested rules?

private void Button_Click(object sender, RoutedEventArgs e)
    {
        WindowMenuPrincipal wmp = new WindowMenuPrincipal();
        wmp.ShowDialog();
    }
  • Can quote references?

  • https://blog.magnusmontin.net/2013/03/24/custom-authorization-in-wpf/

  • the article talks about authorization, where exactly you say there should be no event ?

  • This previously informed article was given in response to how to use wpf with mvvm without using events, but it was not justified why the event could not be used. Follow the original link for further clarification https://social.msdn.microsoft.com/Forums/vstudio/en-US/72d4eced-f3b8-4898-a7ff-5f8f6e763f0e/wpf-and-mvvm-with-login-authentication?forum=wpf Where it reads "suggested not to have any Click Events"

  • Eu sou muito novo para o WPF But you’re wise beyond your years, so don’t give up.

Show 1 more comment

1 answer

5


This is about MVVM and not about WPF. Of course, WPF usually uses MVVM, but nothing prevents it from doing through event handlers and abandoning MVVM. Some people think it’s sacrilege, but the mechanism exists and it’s valid if you know what you’re doing. So better understand how MMVM works (it’s much more complicated than these links, I advise to buy a good book):

The MMVM argues that the visual presentation should be completely isolated from the presentation control, thus the view is created by a designer or UX professional and the shape of the "screen" works is created by a programmer. When you use event handlers in code Behind ends up mixing things up. The MVVM preaches the use of Command design standard to handle the actions the screen triggers or needs updating.

About Command:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.