创建 WPFon showdialog 事件

发布于 2024-11-16 12:57:09 字数 1622 浏览 3 评论 0原文

创建一个新窗口弹出窗口,

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 中的存储过程并返回一个对象,

但是当应用程序运行时,单击在以下行中显示弹出窗口 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}"

如果我删除此代码,它可以工作,但数据不会明显加载。

所以我相信我需要做的是绑定 datagrid onShowDialog 方法。

我如何创建这个?

或者有没有更好的方法使用实体框架来做到这一点,我习惯了 ASP.NET,在 ASP.NET 中,使用 DATAGRIDS 似乎更容易,尽管功能稍弱一些。

非常感谢

I am creating a new window popup window using

PopupWindows.PaymentsSummary paymentsSummary = new PopupWindows.PaymentsSummary  
paymentsSummary.ParentWindow = Window.GetWindow(this);
paymentsSummary.ShowDialog();

on my load function in the Payment summary window I have

    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);
    }

The function is

    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);
        }
    }

The above code calls a Stored Proc in SQL Server and returns an object,

However when the app runs I get the error when clicking to show the popup on the following line paymentsSummary.ShowDialog();

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

I have worked that down to the following code in the XAML for the datagrid

DataGrid  ItemsSource="{Binding}" Grid.Column="{Binding}"

If i remove this code it works but the data doesnt load obvioulsy.

So what I believe I need to do is bind the datagrid onShowDialog method.

How do i create this ?

Or is there a better way of doing this using the Entity framework, im used to ASP.NET where working with DATAGRIDS seem easier, if ablight less powerful.

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江湖正好 2024-11-23 12:57:09

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

  1. 选择急切加载的数据(更改 getPaymentRecordsByPinId)。
  2. 弹出窗口打开时不要处置 dbEntities。

Your problem is lazy loading!, you got 2 options:

  1. select the data with eager loading (change the getPaymentRecordsByPinId).
  2. do not dispose the dbEntities while popup is open.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文