c# - Can I bind two list of different type together? -


i have question binding in mvvm pattern. let's have 3 classes myview, myviewmodel , mymodel. each 1 containing static list:

static public list<line> myviewlist;             (for myview)  static public list<myviewmodel> myviewmodellist; (for myviewmodel)  static public list<mymodel> mymodellist;         (for mymodel) 

is possible bind myviewlist myviewmodellist , myviewmodellist mymodellist ?

are asking if can bind 3 collections itemscontrols?

if so, yes - using compositecollection

<listbox name="mylistbox" height="300" width="200" background="white">   <listbox.itemssource>     <compositecollection>       <collectioncontainer         collection="{binding source={staticresource greekgodsdata}}" />       <collectioncontainer         collection="{binding source={staticresource greekheroesdata}}" />       <listboxitem foreground="red">other listbox item 1</listboxitem>       <listboxitem foreground="red">other listbox item 2</listboxitem>     </compositecollection>   </listbox.itemssource> </listbox> 

above code msdn documentation.

if asking whether can bind 3 static lists eachother, not directly. bindings meant used bind ui backing viewmodels, not bind multiple static collections eachother. can achieved exposing yet static collection getter this:

var col1 = new list<long>(); var col2 = new list<string>();  var totalcol = new list<object>(); totalcol.addrange(col1); totalcol.addrange(col2); 

please note there seems fundamentally wrong design if need collection of views, viewmodels , models. unless have scenario don't understand, :)


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -