.net - Printing in WPF with MVVM - Display PrintDialog from view, but print with ViewModel -
first, take @ this question , answer. in supplied code in answer, there no call printdialog.showdialog()
, example using dialog object print something.
however, printdialog
view, , visual print view, think of should go in view. data view in viewmodel, view print should built view, fired off printer (just view fires off visuals screen). right way think of mvvm in manner?
i thinking of displaying printdialog user view, passing dialog viewmodel printing, seems break idea behind mvvm.
first, moderators typically close open ended, discussion questions this. should narrow question can definitively answered.
second, time pass "view" oriented viewmodel, violating separation of concerns. also, activity in viewmodel block unit test completing execution should immediate red flag breaking mvvm. in case, print dialog displaying , waiting input or being in modal state cause unit test time out or hang.
the solution pass service class in performs work of printing grid, showing dialog, , whatever work required job done. in mvvm, of use dependency injection (di) (i use mef). create service same interface tests use wouldn't block execution. service, in case, view layer service, , should have no dependency viewmodel. thing viewmodel knows has service interface call into, , thing service knows viewmodel interface implements interaction (unless can set needed data on service through it's own interface).
for further reference when think might taking wrong approach ooad, see solid (object-oriented design). isn't definitive, excellent guidance.
Comments
Post a Comment