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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -