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); } }
public void AddLog(string log) { this.theListBox.Items.Add(log); ListBoxAutomationPeer listBoxAutomationPeer = (ListBoxAutomationPeer)UIElementAutomationPeer.CreatePeerForElement(this.theListBox); IScrollProvider pattern = (IScrollProvider)listBoxAutomationPeer.GetPattern(PatternInterface.Scroll); ScrollAmount scrollAmount = ScrollAmount.LargeIncrement; ScrollAmount scrollAmount1 = ScrollAmount.NoAmount; if (pattern.VerticallyScrollable) { pattern.Scroll(scrollAmount1, scrollAmount); } }
public static void ScrollToBottom(this ListBox source) { ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)UIElementAutomationPeer.CreatePeerForElement(source); IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); ScrollAmount scrollVertical = ScrollAmount.LargeIncrement; ScrollAmount scrollHorizontal = 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 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 WriteResponseLine(string responseLine) { listBox_Responses.Items.Add(responseLine); ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(listBox_Responses); IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); ScrollAmount scrollVertical = ScrollAmount.LargeIncrement; ScrollAmount scrollHorizontal = ScrollAmount.NoAmount; if (scrollInterface.VerticallyScrollable) { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } }
private void scrollToBottom() { IScrollProvider scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); ScrollAmount scrollVertical = ScrollAmount.LargeIncrement; ScrollAmount scrollHorizontal = ScrollAmount.NoAmount; try { scrollInterface.Scroll(scrollHorizontal, scrollVertical); } catch (Exception) { } }
private void Items_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { ListBoxAutomationPeer svAutomation = ScrollViewerAutomationPeer.CreatePeerForElement(this.ListBox) as ListBoxAutomationPeer; IScrollProvider scrollInterface = svAutomation.GetPattern(PatternInterface.Scroll) as IScrollProvider; ScrollAmount scrollVertical = ScrollAmount.LargeIncrement; ScrollAmount scrollHorizontal = ScrollAmount.NoAmount; // If the vertical scroller is not available, the operation cannot be performed, which will raise an exception. if (scrollInterface != null && 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 void EnsureVisible(int index) { Core.Focus(FocusState.Pointer); Core.ScrollIntoView(Core.Items[index]); Core.UpdateLayout(); if (Core.ContainerFromIndex(index) == null) { ListBoxAutomationPeer peer = new ListBoxAutomationPeer(Core); var scroll = peer.GetPattern(PatternInterface.Scroll) as IScrollProvider; scroll.SetScrollPercent(scroll.HorizontalScrollPercent, 0); Core.UpdateLayout(); while (Core.ContainerFromIndex(index) == null) { scroll.Scroll(ScrollAmount.NoAmount, ScrollAmount.LargeIncrement); Core.UpdateLayout(); } } }
static void EnsureVisible(ListBox listBox, int index) { listBox.Focus(); listBox.ScrollIntoView(listBox.Items[index]); listBox.UpdateLayout(); if (listBox.ItemContainerGenerator.ContainerFromIndex(index) == null) { ListBoxAutomationPeer peer = new ListBoxAutomationPeer(listBox); var scroll = peer.GetPattern(PatternInterface.Scroll) as IScrollProvider; scroll.SetScrollPercent(scroll.HorizontalScrollPercent, 0); listBox.UpdateLayout(); while (listBox.ItemContainerGenerator.ContainerFromIndex(index) == null) { scroll.Scroll(ScrollAmount.NoAmount, ScrollAmount.LargeIncrement); listBox.UpdateLayout(); } } }
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); } }
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; } }