在Silverlight 4插入后无法刷新/更新数据网格 [英] Unable to refresh/update data grid after insert in Silverlight 4
问题描述
我正在创建一个主版本的silverlight页面,并且在插入新的记录后更新datagrid时遇到麻烦。在页面顶部,我有文本框输入信息,当用户点击保存我想要的信息自动更新在数据库中,并显示在datagrid,而不刷新屏幕。
I am creating a master detials silverlight page and am having trouble updating the datagrid after inserting a new record. On the top of the page I have text boxes to enter information, when a user clicks on save I would like the information automatically updated in the database and displayed on the datagrid without refreshing the screen.
我可以将信息保存到数据库中,而不用担心数据网格会随着新的更改而被刷新。
I am able to save the information to the db with no problems its just trying to get the datagrid to refresh with the new changes.
SAVE按钮的一些代码如下:
Some of my code behind for the SAVE button is below:
ViewModel.UpdateWorkflow(summary, reason, Email);
LoadOperation<Document> lo = _Context.Load<Document>(_Context.GetDocumentsQuery(_DocID), rtRefresh, null);
rtRefresh的代码:
The code for rtRefresh:
private void rtRefresh(LoadOperation<Document> oLoadOperation)
{
if (oLoadOperation.IsComplete)
{
ViewModel.GetDocuments(_DocID);
}
}
我将xml文件中的ViewModel设置为: / p>
I set the ViewModel in the xaml file as:
<controls:ChildWindow.Resources>
<viewModel:DocumentChildWindowViewModel x:Key="ViewModel" />
</controls:ChildWindow.Resources>
代码隐藏中的ViewModel:
And the ViewModel in the code-behind:
ViewModel = Resources["ViewModel"] as DocumentChildWindowViewModel;
任何帮助不胜感激,谢谢。
Any help would be appreciated, thank you.
推荐答案
在我的ViewModel中,我最初创建一个新的DomainContext():
In my ViewModel I initially create a new DomainContext():
public DocumentWindowViewModel()
{
_Context = new appDomainContext();
WireCommands();
}
最后我必须将以下行复制到我的查询中:
I ended up having to copy the following line to my query:
_Context = new appDomainContext();
并粘贴到从数据库中获取值的函数:
And paste to the function that grabs the values from the database:
public void GetDocuments(int dID)
{
_Context = new appDomainContext(); //ADDED THIS LINE TO FIX MY ISSUE
_Context.Load(_Context.GetDocumentsQuery(dID), dlo =>
{
DocumentsView = dlo.Entities;
}, null);
}
}
_Context保留旧值。这清除了_Context,并允许我在_Context中获取更新的数据。
the _Context was keeping old values. This cleared the _Context and allowed me to have the updated data in the _Context.
这篇关于在Silverlight 4插入后无法刷新/更新数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!