I am recreating a small app in WPF and I am trying to use MVVM where it makes sense. I started out thinking I would use it 100% of the time, and so far I have, but I’ve come to the conclusion that strict MVVM (no code-behind whatsoever) is not necessarily a positive thing.
Now I am trying to make a user control that will bind to a list and create a regular button for every item in the list. (Essentially I’m recreating a list-box but with a different style.) I am making this user control specifically to avoid creating the buttons on the fly in the main window’s code-behind, but I am thinking that since everything is essentially “view”, and all logic will be done elsewhere, I can just add the buttons in the code behind without technically breaking MVVM. Is this line of thinking correct, deeply flawed or somewhere in between? Thanks for any help!
MVVM doesn’t forbid the use of code-behind… sometimes code-behind is the right place to do something, as long as it’s purely UI-related.
However in that case I don’t see the benefit of creating those buttons in code-behind, when you can easily make an
ItemsControlwith anItemTemplatethat will display buttons for each item in your collection.