1 #region DataGrid 跨线程委托输出显示方法 姜彦20180315 1439 2 /// <summary> 3 /// DataGrid控件直接接受串口返回数据委托 4 /// </summary> 5 /// <param name="e"></param> 6 public delegate void DataGridReceiverDelegate(TSerialPortController.ReceivedEventArgs e); 7 public void DataGridReceiver(TSerialPortController.ReceivedEventArgs e) 8 { 9 FrameContent frameData = new FrameContent(); 10 frameData.Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); 11 frameData.DataContent = e._ReceiveData; 12 _FrameContents.Add(frameData); 13 } 14 public void DataGridReceiverShow(TSerialPortController.ReceivedEventArgs e) 15 { 16 this.dgFormula.Dispatcher.Invoke(new DataGridReceiverDelegate(DataGridReceiver), e); 17 } 18 19 /// <summary> 20 /// DataGrid控件输出FrameContent对象委托 21 /// </summary> 22 /// <param name="frameContent"></param> 23 public delegate void DataGridTextBoxShowDelegate(FrameContent frameContent); 24 public void DataGridTextBox(FrameContent frameContent) 25 { 26 _FrameContents.Add(frameContent); 27 dgFormula.ScrollIntoView(_FrameContents[_FrameContents.Count - 1], dgFormula.Columns[0]);//滚动条自动跟踪 姜彦20180315 1929 28 } 29 30 /// <summary> 31 /// 将数据显示到DataGrid表格中 32 /// </summary> 33 /// <param name="frameContent"></param> 34 public void DataGridTextBoxShow(FrameContent frameContent) 35 { 36 this.dgFormula.Dispatcher.Invoke(new DataGridTextBoxShowDelegate(DataGridTextBox), frameContent); 37 } 38 39 40 #endregion
1 #region CheckBox计数跨线程委托输出方法 2 3 /// <summary> 4 /// CheckBox接收数据计数委托 5 /// </summary> 6 /// <param name="count"></param> 7 private delegate void CboxCountShowDelegate(int count); 8 private void CboxCount(int count) 9 { 10 if (cboxCount.IsChecked == true) 11 { 12 cboxCount.Content = "计数:" + count.ToString(); 13 } 14 } 15 16 /// <summary> 17 /// CheckBox计数显示 18 /// </summary> 19 /// <param name="count"></param> 20 private void CboxCountShow(int count) 21 { 22 this.cboxCount.Dispatcher.Invoke(new CboxCountShowDelegate(CboxCount), count); 23 } 24 25 #endregion