c# - MVVM passing control handle to the model -
in model using external .dll file needs handle ui control in order display images on it. guess .dll related logic belongs model - not ui.
i have view. inside view i've got:
<windowsformshost x:name="winformshost" horizontalalignment="stretch" verticalalignment="stretch" margin="5,0,5,0"/>
now, in model need handle control placed in windowsfromshost. doing passing reference windows formshost viewmodel:
//view public mainwindow() { initializecomponent(); datacontext = new mainwindowviewmodel(this.winformshost); }
then in viewmodel, passing model:
public mainwindowviewmodel (windowsformshost containerforrenderpanel) { model = new model (containerforrenderpanel); }
finally in model, creating new control , have access handle within model:
public class model : bindablebase { private windowsformshost renderpanelcontainer; public windowsformshost renderpanelcontainer { { return renderpanelcontainer; } set { setproperty(ref renderpanelcontainer, value); } } public model(windowsformshost container) { renderpanelcontainer = container; renderpanelcontainer.child = new system.windows.forms.panel(); } }
i know approach violates mvvm pattern. how can pass handle view's control model?
create observable collection of object type panel. bind collection yours windowsformshost child element.
Comments
Post a Comment