Tuesday, December 23, 2014

C# WPF, Access Parent Window Method from Child Window

For access parent window method from child window, first make parent window method as PUBLIC, then follow below code for child window.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//Declear ParentWindow as GlobalPreview
        SupplierDueListUI globalPrewindow;

public SupplierDueCollectionUI(SupplierDueListUI prewindow)
        {
            InitializeComponent();
            globalPrewindow = prewindow; // Initial prewindow
        }

private void btnUpdatePayment_Click(object sender, RoutedEventArgs e)
        {
            PurchaseInfo purchaseInfoObj = new PurchaseInfo();

            purchaseInfoObj.Id = this._purchaseInfoObj.Id;
            purchaseInfoObj.ProductId = this._purchaseInfoObj.ProductId;
            purchaseInfoObj.SupplierId = this._purchaseInfoObj.SupplierId;
            purchaseInfoObj.TotalDue = Convert.ToInt32(txtTotalDue.Text);
            purchaseInfoObj.TotalPay = Convert.ToInt32(txtTotalPay.Text);

            if (purchaseInfoObj.TotalDue <= 0)
            {
                purchaseInfoObj.IsFullPaid = true;
            }

            _purchaseManagerObj.UpdatePurchasePayment(purchaseInfoObj);

            globalPrewindow.LoadAllPurchaseDueBill(); //Load Parent window method

            MessageBox.Show("Successfully Updated", "Success!", MessageBoxButton.OK, MessageBoxImage.Information);

            this.Close();
        }

No comments:

Post a Comment