【问题标题】:Create WPFon showdialog event创建 WPFon showdialog 事件
【发布时间】: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


    【解决方案1】:

    您的问题是延迟加载!,您有 2 个选项:

    1. 选择预先加载的数据(更改 getPaymentRecordsByPinId)。
    2. 不要在弹出窗口打开时释放 dbEntities。

    【讨论】:

    • 我以为存储过程 (getPaymentRecordsByPinId) 中的所有数据都是在运行时加载的?并被分配到 datagrid.DataContent... 如果不是这种情况,我该如何更改 SP 以便它加载急切加载?使用 linq 获取数据可以正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-27
    • 2016-08-07
    • 2011-06-04
    相关资源
    最近更新 更多