c# - Is it an antipattern to use both traditional click events and ICommand? -


generally, think it's practice use icommands handle button clicks need (such save user input). however, when button strictly on ui, open modal dialog, view model doesn't need handle that, or aware happened. in such cases, seems makes more sense use button's click event handler, mixing , matching seems potential anti-pattern. correct in thinking so?

for example:

var openmodalbutton = new button(); openmodalbutton.click += onmodalbuttonclick;  //elsewhere in view... var saveinputbutton = new button { command = _vm.saveinput }; 

it's not inherently clear looking @ code why 1 uses command, , why 1 uses click event.

jedediah,

i , mix , match. (for me) there 1 or 2 cases this, , idea of patterns , architecture make code easier read , simplify things. adding lot of code ensure mvvm pattern followed seems complicates things in case. said, way i've seen handled bind button viewmodel icommand, , use "mediator" or "service" launch dialog. google search on: "how handle opening modal dialog mvvm way " and/or see:

open dialog in wpf mvvm

the "pretty" way make modal dialog in wpf prism , mvvm pattern

handling dialogs in wpf mvvm

good luck!

dave


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -