c# - Binding two viewmodel's with different hierarchy to one model -


i have viewport3d entities, , treeview hierarchical structure of entities. treeview binded class hierarchy, this:

public class somedataobject {     private observablecollection<somedataobject> _children;     private string _otherproperty;      public somedataobject()     {         this._children = new observablecollection<somedataobject>();         //other initialization     }      public observablecollection<somedataobject> children     {                 {             return this._children;         }         set{ _children = value; }     }      public string otherproperty     {                 {             return this._otherproperty;         }          set{ _otherproperty = value; }       } } 

i bind viewport otherproperty of objects, without hierarchy. viewport provides binding observablecollection, not include ancestors. therefore not have access otherproperty in lower levels.

i think 2 separate viewmodels, don't know how design communication between different viewmodel's.

i found solution: http://blog.quantumbitdesigns.com/2008/07/22/programmatically-selecting-an-item-in-a-treeview/ of course roundabout way. automatically update changes in viewmodels , model.

what best solution in such cases?

edit: xaml treeview:

    <treeview grid.column="0" name="maintreeview">       <treeview.resources>         <hierarchicaldatatemplate datatype="{x:type wpftreeviewtricks:somedataobject}"  itemssource="{binding path=children}">           <stackpanel orientation="horizontal">             <textblock text="treeviewitem:"/>             <textblock margin="1,0,0,0" text="{binding path=otherproperty}"/>           </stackpanel>         </hierarchicaldatatemplate>       </treeview.resources>     </treeview> 

and it's work.

enter image description here

the problem bind hierarchical structure viewport, beacase viewport allow binding in following way:

<ht:helixviewport3d itemssource="{binding objects}" background="{ht:lineargradientbrush gray, white}"/> 

where objects property of datacontext:

public observablecollection<visual3d> objects { get; set; } 


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -