Home > Mobile >  WPF multiple UI Update Simultaneously
WPF multiple UI Update Simultaneously

Time:12-16

I have a datagrid (Cart actually) in a usercontrol and a button (called "Add") in it. below is the screenshot link.

https://photos.app.goo.gl/ftGn4e36REwxHVwb9

when i click on this ADD button a window opens showing products there i put quantity and other details and click submit on this this 2nd window . Below is the screenshot link -

https://photos.app.goo.gl/ftBsx1TdKC4WyLNz9

now the problem is when i click on this submit button there is a method CALled Load that updates the datagrid is called LoadDGStockIN() is called by the button method 'BtnActionSaveNewStockntry()' but no change or update in Datagrid that in usercontrol ui.

plz help i am very new in this field. this is the viewmodel for both the UI.

using Pharma.Model;
using Pharma.View;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;

namespace Pharma.ViewModel
{
    internal class VM_StockIn : INotifyPropertyChanged
    {
        #region get set properties
        private  string _VendorName;
        public  string VendorName
        {
            get { return _VendorName; }
            set { _VendorName = value; }
        }

        private  string _MRP;
        public  string MRP
        {
            get { return _MRP; }
            set { _MRP = value; }
        }


        #endregion
        public VM_StockIn()
        {
            MRP = "contrustor loaded";
        }


        #region Button ADD NEW STOCK
        
        private ICommand _BtnAddNewStock;
        public ICommand BtnAddNewStock
        {
            get 
            {
                return _BtnAddNewStock ?? (_BtnAddNewStock = new CommandHandler.CommandHandler(() => BtnAddNewStock_Action(), () => CanExecute)); 
            }
        }

        

        BackgroundWorker backgroundWorker = new();
        Window_StockEntry window;
        private void BtnAddNewStock_Action()
        {
            window = new();
            window.Show();
            threadNo = Thread.CurrentThread.ThreadState.ToString();

        }

        

        #endregion

        #region Button New Stock Entry SAVE
        //public ICommand btnNewStockEntrySave { get; set; }

        

        
        #endregion

        private ObservableCollection<Stock> _DGISrcStockIn = new ObservableCollection<Stock>();
        public ObservableCollection<Stock> DGISrcStockIn
        {
            get { return _DGISrcStockIn; }
            set { _DGISrcStockIn = value; }
        }

        public void LoadDGStockIN()
        {
            Thread.Sleep(1000);
            DGISrcStockIn = new ObservableCollection<Stock>()
            {
                new Stock { SlNo = 01, AvailableQty = 1254, BatchNo = "DF7SE4B3" },
                new Stock { SlNo = 01, AvailableQty = 1254, BatchNo = "DF7SE4B3" },
                new Stock { SlNo = 01, AvailableQty = 1254, BatchNo = "DF7SE4B3" },
                new Stock { SlNo = 01, AvailableQty = 1254, BatchNo = "DF7SE4B3" },
                new Stock { SlNo = 01, AvailableQty = 1254, BatchNo = "DF7SE4B3" },
                new Stock { SlNo = 01, AvailableQty = 1254, BatchNo = "DF7SE4B3" },
                new Stock { SlNo = 01, AvailableQty = 1254, BatchNo = "DF7SE4B3" },
                new Stock { SlNo = 01, AvailableQty = 1254, BatchNo = "DF7SE4B3" },
                new Stock { SlNo = 01, AvailableQty = 1254, BatchNo = "DF7SE4B3" },
                new Stock { SlNo = 81, AvailableQty = 1254, BatchNo = "DF7SE4B3" }
            };

            OnPropertyChanged(nameof(DGISrcStockIn));

            //MessageBox.Show("Datagrid Load Complete");
            VendorName = "new name";
            OnPropertyChanged(nameof(VendorName));
            MRP = "NO MRP 01";
            OnPropertyChanged(nameof(MRP));
            //OnPropertyChanged(nameof(View.User_Control.UC_StockIn));
        }

        #region OnProperty Block
        public event PropertyChangedEventHandler? PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion

        #region button New Stock Entry SAVE

        private ICommand _btnNewStockEntrySave;
        public ICommand btnNewStockEntrySave
        {
            get 
            {
                return _btnNewStockEntrySave ?? (_btnNewStockEntrySave = new CommandHandler.CommandHandler(() => BtnActionSaveNewStockntry(), () => CanExecute)); 
            }
        }

        public bool CanExecute 
        {
            get { return true;  }
        }


        
        private void BtnActionSaveNewStockntry()
        {
           
              LoadDGStockIN();
            
        }



        #endregion

    }
}

CodePudding user response:

Your ObservableCollection _DGISrcStockIn does not use the OnPropertyChanged interface. You have to call it after the public set like so

private ObservableCollection<Stock> _DGISrcStockIn = new ObservableCollection<Stock>();
public ObservableCollection<Stock> DGISrcStockIn
{
    get { return _DGISrcStockIn; }
    set { _DGISrcStockIn = value; OnPropertyChanged(); }
}

CodePudding user response:

I can not see any code, where you add an item to the observable list, after submit of the dialog.

the function "LoadDGStockIN" will be called and there is a initialization of the Property "DGISrcStockIn" with always the same static items.

You need to extract the data from the dialog and add them to the bound observable list.

  • Related