c# - Unable to refresh/update data grid after insert in Silverlight 4 -
i creating master detials silverlight page , having trouble updating datagrid after inserting new record. on top of page have text boxes enter information, when user clicks on save information automatically updated in database , displayed on datagrid without refreshing screen.
i able save information db no problems trying datagrid refresh new changes.
some of code behind save button below:
viewmodel.updateworkflow(summary, reason, email); loadoperation<document> lo = _context.load<document>(_context.getdocumentsquery(_docid), rtrefresh, null);
the code rtrefresh:
private void rtrefresh(loadoperation<document> oloadoperation) { if (oloadoperation.iscomplete) { viewmodel.getdocuments(_docid); } }
i set viewmodel in xaml file as:
<controls:childwindow.resources> <viewmodel:documentchildwindowviewmodel x:key="viewmodel" /> </controls:childwindow.resources>
and viewmodel in code-behind:
viewmodel = resources["viewmodel"] documentchildwindowviewmodel;
any appreciated, thank you.
i'm assuming datagrid bound ienumerable, maybe list<>? have tried using observablecollection<>? if bound observablecollection, let ui know when collection has changed.
<usercontrol x:class="silverlightapplication1.mainpage" 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:local="clr-namespace:silverlightapplication1" xmlns:data="clr-namespace:system.windows.controls;assembly=system.windows.controls.data" mc:ignorable="d" d:designheight="300" d:designwidth="400"> <usercontrol.datacontext> <local:mainpage_viewmodel/> </usercontrol.datacontext> <stackpanel> <data:datagrid itemssource="{binding mycollection}"> </data:datagrid> </stackpanel>
public class mainpage_viewmodel : inotifypropertychanged { public observablecollection<object> mycollection { { return mycollection; } set { if (mycollection != value) { mycollection = value; onpropertychanged("mycollection"); } } } private observablecollection<object> mycollection = new observablecollection<object>(); public void loaddata() { //execute load method, assign result mycollection } #region inotifypropertychanged members public event propertychangedeventhandler propertychanged; public void onpropertychanged(string propertyname) { if (propertychanged != null) { propertychanged(this, new propertychangedeventargs(propertyname)); } } #endregion }
Comments
Post a Comment