private void AddInfoToEventListFromGuiThread(string info) { // here we are sure to be within GUI thread and we can // safely access the list box lstEvents.Items.Add(info); /// ... /// [threading sync gui thread] // Ensure last added item is visible System.Windows.Automation.Peers.ListBoxAutomationPeer svAutomation = (System.Windows.Automation.Peers.ListBoxAutomationPeer) System.Windows.Automation.Peers.ScrollViewerAutomationPeer.CreatePeerForElement(lstEvents); System.Windows.Automation.Provider.IScrollProvider scrollInterface = (System.Windows.Automation.Provider.IScrollProvider)svAutomation.GetPattern(System.Windows.Automation.Peers.PatternInterface.Scroll); System.Windows.Automation.ScrollAmount scrollVertical = System.Windows.Automation.ScrollAmount.LargeIncrement; System.Windows.Automation.ScrollAmount scrollHorizontal = System.Windows.Automation.ScrollAmount.NoAmount; //If the vertical scroller is not available, the operation cannot be performed, which will raise an exception. if (scrollInterface == null) { return; } if (scrollInterface.VerticallyScrollable) { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } //lstEvents..TopIndex = lstEvents.Items.Count - 1; //lstEvents.SelectedIndex = -1; }
private void PrintLog(string message) { if (!Log.Dispatcher.CheckAccess()) { this.Dispatcher.Invoke(new PrintLogDelegate(PrintLog), message); return; } Log.Items.Add(DateTime.Now.ToString("HH:mm:ss") + " " + message); try { ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(Log); IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); System.Windows.Automation.ScrollAmount scrollVertical = System.Windows.Automation.ScrollAmount.LargeIncrement; System.Windows.Automation.ScrollAmount scrollHorizontal = System.Windows.Automation.ScrollAmount.NoAmount; if (scrollInterface.VerticallyScrollable) { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } } catch { // 하단 내리기 실패. } }
// from https://stackoverflow.com/a/18305272 private void ListBoxScrollToBottom(ListBox listBox) { ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)UIElementAutomationPeer.CreatePeerForElement(chatMessages); IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); System.Windows.Automation.ScrollAmount scrollVertical = System.Windows.Automation.ScrollAmount.LargeIncrement; System.Windows.Automation.ScrollAmount scrollHorizontal = System.Windows.Automation.ScrollAmount.NoAmount; if (scrollInterface.VerticallyScrollable) { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } }
private void HotReloadingPadControl_Loaded(object sender, RoutedEventArgs e) { ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(listBox); IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); System.Windows.Automation.ScrollAmount scrollVertical = System.Windows.Automation.ScrollAmount.LargeIncrement; System.Windows.Automation.ScrollAmount scrollHorizontal = System.Windows.Automation.ScrollAmount.NoAmount; //If the vertical scroller is not available, the operation cannot be performed, which will raise an exception. if (scrollInterface.VerticallyScrollable) { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } }
private void ConsoleLog_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { var listview = this.ConsoleBox; if (listview.Items.Count > 5) { ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(listview); IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); System.Windows.Automation.ScrollAmount scrollVertical = System.Windows.Automation.ScrollAmount.LargeIncrement; System.Windows.Automation.ScrollAmount scrollHorizontal = System.Windows.Automation.ScrollAmount.NoAmount; if (scrollInterface.VerticallyScrollable) { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } } }
public MainWindow() { InitializeComponent(); this.DataContext = new MainWindowViewModel(); ViewModel.Messages.CollectionChanged += (s, e) => { ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(lstMessages); IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); System.Windows.Automation.ScrollAmount scrollVertical = System.Windows.Automation.ScrollAmount.LargeIncrement; System.Windows.Automation.ScrollAmount scrollHorizontal = System.Windows.Automation.ScrollAmount.NoAmount; //If the vertical scroller is not available, the operation cannot be performed, which will raise an exception. if (scrollInterface.VerticallyScrollable) { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } }; }
private void UpdateData(string strData) { if (strData == strFlag) { bRFIDConnected = true; btnCOMStart.IsEnabled = false; btnCOMStop.IsEnabled = true; lblStatus.Content = "Status: COM port opened. Reader mode changed to RFID scanning."; sr.Write("RFUFM,00\r"); tmrStatus.Start(); } if (strConfirmOK.Contains(strData)) { return; } strData = (iCounter++).ToString() + ": " + strData; lst.Items.Add(strData); if (lst.Items.Count > 0) { lst.SelectedIndex = lst.Items.Count - 1; // Auto scroll solution from this link >> http://stackoverflow.com/questions/2337822/wpf-listbox-scroll-to-end-automatically ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(lst); IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); System.Windows.Automation.ScrollAmount scrollVertical = System.Windows.Automation.ScrollAmount.LargeIncrement; System.Windows.Automation.ScrollAmount scrollHorizontal = System.Windows.Automation.ScrollAmount.NoAmount; //If the vertical scroller is not available, the operation cannot be performed, which will raise an exception. if (scrollInterface.VerticallyScrollable) { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } } if (rdoManual.IsChecked == true) { lblStatus.Content = "Info: Press trigger to read tag."; } }
void AutoScroll() { try { ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(lstview_anzeige); IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); System.Windows.Automation.ScrollAmount scrollVertical = System.Windows.Automation.ScrollAmount.LargeIncrement; System.Windows.Automation.ScrollAmount scrollHorizontal = System.Windows.Automation.ScrollAmount.NoAmount; //If the vertical scroller is not available, the operation cannot be performed, which will raise an exception. if (scrollInterface.VerticallyScrollable) { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } } catch (Exception ex) { log.ExLogger(ex); } }
private void UpdateLog(string entry) { entry = DateTime.Now + " - " + entry; try { File.AppendAllLines(GetLogPath(), new string[] { entry }); } catch { } logListBox.Items.Add(entry); ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(logListBox); IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); System.Windows.Automation.ScrollAmount scrollVertical = System.Windows.Automation.ScrollAmount.LargeIncrement; System.Windows.Automation.ScrollAmount scrollHorizontal = System.Windows.Automation.ScrollAmount.NoAmount; if (scrollInterface.VerticallyScrollable) { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } }
void System.Windows.Automation.Provider.IScrollProvider.Scroll(System.Windows.Automation.ScrollAmount horizontalAmount, System.Windows.Automation.ScrollAmount verticalAmount) { }
private void serial_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { SemaphoreDataReceived.WaitOne(); SerialPort mySerialP = (SerialPort)sender; result = new List <byte>(); byte[] firstReadData = new byte[mySerialP.BytesToRead]; List <byte> metaData = new List <byte>(); List <byte> lastReceivedTranMsg = new List <byte>(); List <char> myMetaData = new List <char>(); mySerialP.Read(firstReadData, 0, firstReadData.Length); metaData.AddRange(firstReadData); string datas = System.Text.Encoding.UTF8.GetString(firstReadData); Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate() { textboxSP.Text += (datas) + "\n"; textboxSP.ScrollToEnd(); //hercul.listboxSP.SelectedIndex = hercul.listboxSP.Items.Count - 1; ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(listboxSP); IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); System.Windows.Automation.ScrollAmount scrollVertical = System.Windows.Automation.ScrollAmount.LargeIncrement; System.Windows.Automation.ScrollAmount scrollHorizontal = System.Windows.Automation.ScrollAmount.NoAmount; //If the vertical scroller is not available, the operation cannot be performed, which will raise an exception. if (scrollInterface.VerticallyScrollable) { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } }); int indexCounter = 0; for (int i = 0; i < metaData.Count; i++) { lastReceivedTranMsg = new List <byte>(); if (metaData.Contains((byte)CommandType.GainOffsetStart)) { if (metaData.Contains((byte)CommandType.GainOffsetEnd)) { int startIndex = metaData.IndexOf((byte)CommandType.StartingProtocol); int endIndex = metaData.IndexOf((byte)CommandType.EndOfProtocol); for (int j = startIndex + 1; j < metaData.Count; j++) { if (metaData[j] == (byte)CommandType.GainOffsetStart) { lastReceivedTranMsg.Clear(); continue; } else if (metaData[j] == (byte)CommandType.GainOffsetEnd) { Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate() { if (!Harf.Content.ToString().Contains(ByteArrayToString(lastReceivedTranMsg.ToArray()))) { Harf.Content = Harf.Content + " " + ByteArrayToString(lastReceivedTranMsg.ToArray()); } lastReceivedTranMsg.Clear(); }); } lastReceivedTranMsg.Add(metaData[j]); } } } if (metaData.Contains((byte)CommandType.StartingProtocol)) { if (metaData.Contains((byte)CommandType.EndOfProtocol)) { int startIndex = metaData.IndexOf((byte)CommandType.StartingProtocol); int endIndex = metaData.IndexOf((byte)CommandType.EndOfProtocol); if (startIndex < endIndex) { for (int j = startIndex; j < metaData.Count; j++) { indexCounter++; if (metaData[j] == (byte)CommandType.EndOfProtocol) { lastReceivedTranMsg.Add(metaData[j]); metaData.RemoveRange(0, startIndex + endIndex); break; } lastReceivedTranMsg.Add(metaData[j]); } myMetaData = System.Text.ASCIIEncoding.ASCII.GetChars(lastReceivedTranMsg.ToArray()).ToList(); string myStringValue = ""; for (int j = 1; j < myMetaData.Count - 1; j++) { myStringValue += myMetaData[j]; } mesuValue = (Convert.ToInt64(myStringValue)); this.Dispatcher.Invoke((Action)(() => { textlist.Add("" + mesuValue); listboxSP.Items.Add(textlist[textlist.Count - 1]); voltagePointCollection.Add(new VoltagePoint(mesuValue, DateTime.Now)); })); i += indexCounter; } else { metaData.RemoveRange(0, startIndex); byte[] secondReadData; do { secondReadData = new byte[mySerialP.BytesToRead]; mySerialP.Read(secondReadData, 0, secondReadData.Length); } while (!secondReadData.Contains((byte)CommandType.EndOfProtocol)); metaData.AddRange(secondReadData); for (int j = startIndex; j < metaData.Count; j++) { if (metaData[j] == (byte)CommandType.EndOfProtocol) { lastReceivedTranMsg.Add(metaData[j]); endIndex = metaData.IndexOf((byte)CommandType.EndOfProtocol); metaData.RemoveRange(0, startIndex + endIndex); break; } lastReceivedTranMsg.Add(metaData[j]); } myMetaData = System.Text.ASCIIEncoding.ASCII.GetChars(lastReceivedTranMsg.ToArray()).ToList(); string myStringValue = ""; for (int j = 0; j < myMetaData.Count - 1; j++) { myStringValue += myMetaData[j]; } mesuValue = (Convert.ToInt64(myStringValue)); this.Dispatcher.Invoke((Action)(() => { textlist.Add("" + mesuValue); listboxSP.Items.Add(textlist[textlist.Count - 1]); voltagePointCollection.Add(new VoltagePoint(mesuValue, DateTime.Now)); })); i += indexCounter; } } } } SemaphoreDataReceived.Release(); } catch (Exception ex) { try { SemaphoreDataReceived.Release(); } catch (Exception) { //throw; } //throw; } }