c# - MVVM and DataGrid View re-use as embedded controls within otherviews with subset data -


okay here's situation. net 4 wpf no silverlight.

i have several views present datagrid showing contents of observable collections e.g.

observablecollection<classaviewmodel> sourcea; observablecollection<classbviewmodel> sourceb; observablecollection<classcviewmodel> sourcec; 

the collections populated call data access layer. can display data enough usercontrol contains datagrid bound appropriate collection. have

  • classaview , classaviewmodel control display of single classa data,
  • classbview , classbviewmodel control display of single classb data
  • classcview , classcviewmodel control display of single classc data

i have:

  • allclassaview , allclassaviewmodel display datagrid data relating classa instances.
  • allclassbview , allclassbviewmodel display datagrid data relating classb instances.

    etc.

now classa contains subset of classb collection , subset of classc collection etc.

in resource file have bound viewmodels , views in following manner (vm , vw namespaces of are) :

<datatemplate datatype="x:type vm:classaviewmodel}">   <vw:classaview/> </datatemplate> 

now hoping use allclassbview or allclassbviewmodel within classaview display subset of classb instances relate it.

what best way call data?

can re-use allclassbview usercontrol display subset of classb observablecollection , best way of doing this?

i don't want place code within classaview.cs file within classaview.xaml or classaviewmodel.

should add new property allclassbview , use filter list? example within classbviewmodel generate list of classbviewmodels (for use in datagrid) can use:

if(this.classa_id!=0) {   list<classbviewmodel> = (from classb in this.datarepository.getclassbs().where(x=>x.classa_id == this.classa_id) select new classbviewmodel()).tolist(); } else {   list<classbviewmodel> = (from classb in this.datarepository.getclassbs() select new classbviewmodel()).tolist(); }  this.sourceb= new observablecollection<classbviewmodel>(all); 

well i've cracked it.

my problem may not have come across clear.

whether solution practice or not don't know.

what have done follows:

i placed property allclassbviewmodel allows me filter list of classbviewmodels relate classa.

public ulong classa_id{get;set;} 

so when allclassbviewmodel builds list of classbviewmodels can filter them by:

if(this.classa_id!=0) {   list<classbviewmodel> = (from classb in this.datarepository.getclassbs().where(x=>x.classa_id == this.classa_id) select new classbviewmodel()).tolist(); } else {   list<classbviewmodel> = (from classb in this.datarepository.getclassbs() select new classbviewmodel()).tolist(); }  this.sourceb= new observablecollection<classbviewmodel>(all); 

i added property , field classaviewmodel of allclassbviewmodel type.

private allclassbviewmodel fieldallclassbviewmodel; public allclassbviewmodel allclassbvm{get{return this.fieldallclassbviewmodel;}} 

i added entry allclassbview classaview had data context bound allclassbvm property within classaviewmodel.

<vw:allclassbview datacontext="{binding allclassbvm}"/> 

no have check through command binding.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -