【发布时间】:2011-06-22 20:11:10
【问题描述】:
我正在使用
创建一个新窗口弹出窗口PopupWindows.PaymentsSummary paymentsSummary = new PopupWindows.PaymentsSummary
paymentsSummary.ParentWindow = Window.GetWindow(this);
paymentsSummary.ShowDialog();
在我的付款摘要窗口中的加载功能上我有
private void Window_Loaded(object sender, RoutedEventArgs e)
{
basepage.payments.BindPaymentSummaryToDataGrid(uiActiveItems, basepage.user.terminal.TerminalId, true);
basepage.payments.BindPaymentSummaryToDataGrid(uiInActiveItems, basepage.user.terminal.TerminalId, false);
}
功能是
public void BindPaymentSummaryToDataGrid(DataGrid dgrid, int terminalId, bool isActivePayment)
{
BLPinNumber pins = new BLPinNumber();
string pinNumber = String.Empty;
long pinId = pins.getPinId(terminalId, ref pinNumber);
using (var dbEntities = new DatabaseAccess.Schema.Entities())
{
dgrid.DataContext = dbEntities.getPaymentRecordsByPinId((int)pinId, isActivePayment);
}
}
以上代码在SQL Server中调用一个Stored Proc并返回一个对象,
但是,当应用程序运行时,单击以在以下行显示弹出窗口时出现错误 paymentSummary.ShowDialog();
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
我已将其简化为数据网格的 XAML 中的以下代码
DataGrid ItemsSource="{Binding}" Grid.Column="{Binding}"
如果我删除此代码,它可以工作,但数据不会加载。
所以我认为我需要做的是绑定数据网格的 onShowDialog 方法。
我如何创建这个?
或者有没有更好的方法使用实体框架来做到这一点,我习惯了 ASP.NET,使用 DATAGRIDS 似乎更容易,如果功能不那么强大。
非常感谢
【问题讨论】:
标签: c# wpf entity-framework-4 wpfdatagrid