void itemscontrol_Loaded(object sender, RoutedEventArgs e) { AutomationPeer ap = FrameworkElementAutomationPeer.CreatePeerForElement(this.AssociatedObject as UIElement); ScrollViewerAutomationPeer avap = (ScrollViewerAutomationPeer)ap.GetPattern(PatternInterface.Scroll); _scrollViewer = (ScrollViewer)avap.Owner; SetBinding( DataContextProperty, new Binding { Path = new PropertyPath("DataContext"), Source = AssociatedObject, Mode = BindingMode.TwoWay }); _dt.Tick += (_, __) => { _scrollViewer.ChangeView(_scrollViewer.HorizontalOffset + HorizontalSpeed, _scrollViewer.VerticalOffset + VerticalSpeed, null, true); _scrollViewer.UpdateLayout(); }; }
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 { // 하단 내리기 실패. } }
public PlayerColumn(MainWindow mw) { InitializeComponent(); MW = mw; svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(listBox_history); }
/// <summary> /// Posune listbox na konec. /// </summary> private void ScrollToBottom(ListBox lbProducts) { ListBoxAutomationPeer svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(lbProducts); if (VisualTreeHelper.GetChildrenCount(lbProducts) > 0) { Border border = (Border)VisualTreeHelper.GetChild(lbProducts, 0); ScrollViewer scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0); scrollViewer.ScrollToBottom(); } }
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 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 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 ScrollTo(CompressedFileSearcher.MatchResult match) { int lineNumber; if (int.TryParse(match.LineNumber, NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out lineNumber)) { var svAutomation = (ListBoxAutomationPeer)ScrollViewerAutomationPeer.CreatePeerForElement(textView); var scrollInterface = (IScrollProvider)svAutomation.GetPattern(PatternInterface.Scroll); double totalCount = Context.Contents.Count; double linePercent = 100.0 * lineNumber / totalCount; try { scrollInterface.SetScrollPercent(System.Windows.Automation.ScrollPatternIdentifiers.NoScroll, linePercent); Trace.WriteLine(string.Format("Selected line {0}, {1}% of {2}", lineNumber, linePercent, totalCount)); } catch (Exception ex) { Trace.WriteLine(ex.Message); } } }
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; } }
/// <summary> /// Gets the <see cref="AutomationPeer"/>s from the <see cref="DataFormAutomationPeer"/>. /// </summary> private void GetChildAutomationPeers() { this._firstItemButtonAutomationPeer = null; this._previousItemButtonAutomationPeer = null; this._nextItemButtonAutomationPeer = null; this._lastItemButtonAutomationPeer = null; this._editButtonAutomationPeer = null; this._newItemButtonAutomationPeer = null; this._deleteItemButtonAutomationPeer = null; this._commitButtonAutomationPeer = null; this._cancelButtonAutomationPeer = null; this._labelAutomationPeers = new List <TextBlockAutomationPeer>(); this._inputControlAutomationPeers = new List <AutomationPeer>(); this._descriptionAutomationPeers = new List <DescriptionViewerAutomationPeer>(); List <AutomationPeer> automationPeers = this._dataFormAutomationPeer.GetChildren(); foreach (AutomationPeer automationPeer in automationPeers) { string className = automationPeer.GetClassName(); if (className == "Button") { ButtonAutomationPeer buttonAutomationPeer = automationPeer as ButtonAutomationPeer; Assert.IsNotNull(buttonAutomationPeer); string automationId = automationPeer.GetAutomationId(); switch (automationId) { case "FirstItemButton": this._firstItemButtonAutomationPeer = buttonAutomationPeer; break; case "PreviousItemButton": this._previousItemButtonAutomationPeer = buttonAutomationPeer; break; case "NextItemButton": this._nextItemButtonAutomationPeer = buttonAutomationPeer; break; case "LastItemButton": this._lastItemButtonAutomationPeer = buttonAutomationPeer; break; case "EditButton": this._editButtonAutomationPeer = buttonAutomationPeer; break; case "NewItemButton": this._newItemButtonAutomationPeer = buttonAutomationPeer; break; case "DeleteItemButton": this._deleteItemButtonAutomationPeer = buttonAutomationPeer; break; case "CommitButton": this._commitButtonAutomationPeer = buttonAutomationPeer; break; case "CancelButton": this._cancelButtonAutomationPeer = buttonAutomationPeer; break; default: Assert.Fail("Unexpected ButtonAutomationPeer."); break; } } else if (className == "TextBlock") { this._changeIndicatorAutomationPeer = automationPeer as TextBlockAutomationPeer; } else if (className == "ScrollViewer") { this._scrollViewerAutomationPeer = automationPeer as ScrollViewerAutomationPeer; Assert.IsNotNull(this._scrollViewerAutomationPeer); List <AutomationPeer> formAutomationPeers = this._scrollViewerAutomationPeer.GetChildren(); for (int i = 0; i < formAutomationPeers.Count; i++) { if (i % 3 == 0) { TextBlockAutomationPeer textBlockAutomationPeer = formAutomationPeers[i] as TextBlockAutomationPeer; if (textBlockAutomationPeer != null) { this._labelAutomationPeers.Add(textBlockAutomationPeer); } } else if (i % 3 == 1) { this._inputControlAutomationPeers.Add(formAutomationPeers[i]); } else { DescriptionViewerAutomationPeer descriptionViewerAutomationPeer = formAutomationPeers[i] as DescriptionViewerAutomationPeer; if (descriptionViewerAutomationPeer != null) { this._descriptionAutomationPeers.Add(descriptionViewerAutomationPeer); } } } } } }