For example, I have a ListView
that contains a ItemClick
event and a SelectionChanged
event. Should I entirely skip the code-behind file and put the event handler in the ViewModel, or should I keep the handler in the code-behind?
To me it doesn't seem logical to skip the code-behind because it seems that event handlers are directly made for UI elements. For example, the sender
parameter and the related EventArgs
parameter typically requires knowledge of a particular type of UI element, and so you would have to cast the sender
object to a UI element type so that you can work with the data. In fact, in some cases the sender
parameter's type is already given:
private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
// In this particular case there is no need to cast the sender parameter to the AutoSuggestBox (UI element!) type because it is already given.
}
Is it safe to work with these UI elements or should UI matters be taken care of in the View only. Please save me from myself. Thanks.