0

私は ObservableCollection である Item ソースを持っていますが、それを更新するたびに。アイテム ソースを削除して返すまで、プログラムはアイテム ソースを表示しません。

私がそれをしているときに、GUIが動かなくなりました。

 private ObservableCollection<DataForTable> _dataForTableRecieved; // a list to update the gui table.


    private void initVariables()
    {
          _dataForTableRecieved = new ObservableCollection<DataForTable>();   
           ThreadGui = new Thread(new ThreadStart(barak));
           ThreadGui.IsBackground = true;
           ThreadGui.Start();
     }


  private void b()
     {
        dataGridData.ItemsSource = "";
        dataGridData.ItemsSource = DataForTableRecieved;
        if (dataGridData.Columns.Count > 5)
        {
            dataGridData.Columns[5].Visibility = Visibility.Collapsed; // column data.
        }
     }

/// <summary>
    /// this method update the datagrid data table with the correct data.
    /// </summary>
    private void updateTablesOfGui()
    {
        DataForTable dt = new DataForTable();
        if (_QAllMessagesRecieved.Count > 0) // check recieve data 
        {


            _indexDataRecieved++;
            dt.LineNumber = (int)_indexDataRecieved;
            DateTime _Time = _QAllDateTimeMessgesRecieved.Dequeue();
            dt.Time = _Time.ToShortDateString() + "  " + _Time.ToLongTimeString() + "." + _Time.Millisecond.ToString();
            dt.RX_TX = "RX";
            byte[] dataArr = _QAllMessagesRecieved.Dequeue();
            dt.MsgType = _pd.ParseMeesage(dataArr, _toCheckCheckSum);
            dt.Data = ConvertFromBytesToString(dataArr);
            dt.ComPortName = "COM";

            this.Dispatcher.Invoke(updateTableGuiDelgate, dt);


        }
  }
    private void barak()
    {

        while (true)
        {
            this.Dispatcher.BeginInvoke(e);
            System.Threading.Thread.Sleep(100);
        }
    }



    /// <summary>
    /// this class contain a row for the data to show in the dataGridReceived
    /// </summary>
    public class DataForTable : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// this method used  for on property change to update the data in the table.
        /// </summary>
        /// <param name="propertyName"></param>
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new        PropertyChangedEventArgs(propertyName));
        }


        private int lineNumber; // the line number of row.            
        /// <summary>
        /// get or set contain the line number to show the data
        /// </summary>
        public int LineNumber
        {
            get { return lineNumber; }
            set
            {
                if (lineNumber != null)
                {
                    lineNumber = value;
                    OnPropertyChanged("LineNumber");
                }
            }
        }

        private string time; // contain the time of the data that has been sent or received. 

        /// <summary>
        /// get or sets the time that has been received.
        /// </summary>
        public string Time
        {
            get { return time; }
            set
            {
                if (time != null)
                {
                    time = value;
                    OnPropertyChanged("Time");
                }

            }
        }


        private string rX_TX; // if it is RX or TX


        /// <summary>
        /// this is the Com Port Name
        /// </summary>
        public string ComPortName
        {
            get { return comPortName; }
            set
            {
                if (comPortName != null)
                {
                    comPortName = value;
                    OnPropertyChanged("ComPortName");
                }
            }
        }

        /// <summary>
        /// get or set contain if this is a data that has been send from the RX or from the TX
        /// </summary>
        public string RX_TX
        {
            get { return rX_TX; }
            set
            {
                if (rX_TX != null)
                {
                    rX_TX = value;
                    OnPropertyChanged("RX_TX");
                }
            }
        }


        private string data; // contain the line of data the has been received.                        

        /// <summary>
        /// get or set the line of data that has been received or sent
        /// </summary>
        public string Data
        {
            get { return data; }
            set
            {
                if (data != null)
                {
                    data = value;
                    OnPropertyChanged("Data");

                }

            }
        }



        private string msgType;// the translation of the data per the XML.


        /// <summary>
        /// get or sets the translation from the xml into the dll
        /// </summary>
        public string MsgType
        {
            get { return msgType; }
            set
            {
                if (msgType != null)
                {
                    msgType = value;
                    OnPropertyChanged("MsgType");
                }

            }
        }

        private string comPortName;


        /// <summary>
        /// this is a constructor for updating the data init all the variables
        /// </summary>
        public DataForTable()
        {
            lineNumber = 0;
            time = "";
            rX_TX = "";
            data = "";
            msgType = "";
            comPortName = "";

        }

    }
4

1 に答える 1

0

割り当てを行う前にこれを試してください:

_dataForTableRecieved.Clear();
_dataForTableRecieved = <the_updated_collection>;
于 2015-09-24T10:04:37.250 に答える