I would like to get some opinions on when / if this is normal, enter the code in codebehind. I have been doing this for less than a year. So, I still consider myself very "green." I come from the background of Delphi. So the learning curve was huge, to say the least - learning WPF, XAML, C #, Unity, Prism, MEF, .NET, MVVM, etc. Fun, but very difficult.
When I first started less than a year ago, the idea in the office was not code in code, if at all possible, and there was no specific code in VM. So, I racked my brains many times to determine how to literally paste everything into a virtual machine and save what I think is a kind of code defined from a virtual machine, only to appear almost every time. Im to the point now, Im starting to think the codebehind is not always bad or "wrong." I recently tried to clear some of our views by trying to insert any code information into a virtual machine that made me find the neat factory class at http://blog.functionalfun.net/2008/09/hooking-up-commands-to-events-in -wpf.html . This allows you to associate redirected events withICommandin a virtual machine. It works like a charm, and I was able to significantly reduce the portion of our code with it. However, after that, I now ask my decision to do this. My approach followed the philosophy that codebehind was bad / wrong, if absolutely necessary. Now that I had a little time to think about it, I'm not very sure that refactoring was a better idea.
Below is an example of a view I reorganized. We have a new account view in which the user enters the SSN and must reinstall the SSN before the new account is created. The view has a label that displays text indicating to the user if the SSN and repeat SSN do not match, and the OK button is not enabled until both of them match. As soon as the SSN and SSN command match, the shortcut disappears (yes, I know ... I hate this, but Im just a developer) and the OK button is on. Thus, hiding / showing the shortcut and turning on / off the OK button is triggered from eventsTextChangedin the SSN and rekey SSN text boxes. Initially, I had logic in the code to compare the two values of the text field and set the viewmodel properties correctly to update the label visibility property and the button properties with the OK buttons (yes, their properties are connected in XAML). Finding this new factory class, I used it to pop all the code in the viewmodel, and the view works the same as before, without the code. After successfully refactoring the view, I now prefer the reorganization decision.
, , SSN . , SSN, OK. viewmodel ? . , viewmodel , , , . - viewmodel, VM, - ?