xaml - WPF MVVM Light dynamic list source on data grid -


okay, have admin screen in application. originally, plan have datagrid each entity , hide/show them. believe there better way 1 data grid. way, not need make add/edit buttons each datagrid (you can't have same name) leads mess of codes , re-writing things feel can made dynamic. so, created custom class called admindatagrid:

public class admindatagrid : datagrid {     public admindatagrid()     {         messenger.default.register<string>(this, "updatedatagrid", (action) => updatedatagrid(action));         messenger.default.register<icollectionview>(this, "receivedriverlist", (x) => this.currentitemssource = x);     }       public void updatedatagrid(string model)     {         switch (model)         {             case "driver":                 messenger.default.send<string>("getdriverslist", "getdriverslist");                 break;             default:                 break;         }     }      #region inpc      public icollectionview currentitemssource { { return (icollectionview)getvalue(currentitemssourceproperty); } set { setvalue(currentitemssourceproperty, value); } }     public static readonly dependencyproperty currentitemssourceproperty =         dependencyproperty.register("currentitemssource", typeof(icollectionview), typeof(admindatagrid), new propertymetadata(null));      #endregion } 

my test case driver list working setting variable. idea using current vms , not having inject different services in admin view model. here xaml:

<localdata:admindatagrid itemssource="{binding currentitemssource, updatesourcetrigger=propertychanged}"                                          selectionmode="single" alternatingrowbackground="gainsboro" autogeneratecolumns="true"                                          selectionunit="fullrow" x:name="lookupsdatagrid" grid.row="0" grid.column="1"/> 

i know wrong code because when select 'driver' option menu of entities not load datagrid list. admindatagrid class in utilities folder created separate class.

once can populate datagrid whatever wish, run logic in code customize columns show. moment, main problem is: why datagrid not updating when itemssource changes?

try binding .

 <localdata:admindatagrid itemssource="{binding currentitemssource, relativesource={relativesource mode=self} , updatesourcetrigger=propertychanged}" 

your currentitemssource property in same datagrid need bind self relativesource


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 -