wpf - MVVM - pass info from MainWindow ViewModel to WinForms based child UserControl -


i'm working on wpf/mvvm application host winforms graphical control display of cad-type geometry.

first, little background.

basically, have mainwindow treeview on left , tabcontrol on right. treeview renders observable collection of treenode objects. based on type of node that's clicked in tree, main window's viewmodel creates instance of appropriate child viewmodel selected tree node (a "workspace"). new workspace added observable collection that's bound tabcontrol - creates new tab item. similar well-known josh smith example.

in xaml of main window, i'm using <datatemplate datatype...>

to instantiate appropriate view created viewmodel.

so far, good. works well. now, here's i'm stuck...

one "type" of tree node represents cad model. when node of type selected, view that's instantiated contains winforms graphical control (wrapped in winformshost usercontrol). underlying winforms control has "loadfile()" method requires filename input.

the object that's rendered tree node in mainwindow contains name of file need load. so, i'm trying figure out best way filename tree node object , pass "loadfile()" method in underlying winforms control.

i have filename in mainwindow's viewmodel @ time create viewmodel cad control (which, in turn, creates view containing winforms control via xaml datatemplate).

every attempt i've made far feels i'm painting myself corner. so, far in weeds, or sound salvageable?

edited post code requested below...

relevant code-behind of user control

public string msifile {     { return (string)getvalue(msifileproperty); }     set { setvalue(msifileproperty, value); } }  public static readonly dependencyproperty msifileproperty =     dependencyproperty.register("msifile", typeof(string), typeof(viewportusercontrol),     new frameworkpropertymetadata(null, new propertychangedcallback(onmsifilechanged)));   private static void onmsifilechanged(    dependencyobject sender, dependencypropertychangedeventargs e) {     console.writeline(e); } 

user control xaml

<usercontrol x:class="trunest.usercontrols.viewportusercontrol"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"              xmlns:vp="clr-namespace:customcontrols;assembly=winforms"              d:designheight="300"              d:designwidth="300"              mc:ignorable="d" loaded="usercontrol_loaded">     <grid>         <windowsformshost horizontalalignment="stretch" verticalalignment="stretch">             <vp:viewportcustomuc x:name="wrapper" />         </windowsformshost>     </grid> </usercontrol> 

code mainwindow viewmodel - triggered when new treenode selected

else if (_selectedtreeviewitem viewportnode) {     viewportnode node = _selectedtreeviewitem viewportnode;     viewportviewmodel workspace = new viewportviewmodel();     workspace.treenode = _selectedtreeviewitem;     workspace.name = string.format("{0}", node.name);     workspaces.add(workspace);     this.setactiveworkspace(workspace); } 


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -