Example #1
0
        /// <summary>
        /// Handles the MouseWheel event of the AssociatedObject control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseWheelEventArgs"/> instance containing the event data.</param>
        void AssociatedObject_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            this.AssociatedObject.Focus();

            int direction = Math.Sign(e.Delta);

            ScrollAmount scrollAmount =
                (direction < 0) ? ScrollAmount.SmallIncrement : ScrollAmount.SmallDecrement;

            if (this.Peer != null)
            {
                IScrollProvider scrollProvider =
                    this.Peer.GetPattern(PatternInterface.Scroll) as IScrollProvider;

                bool shiftKey = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift;

                if (scrollProvider != null && scrollProvider.VerticallyScrollable && !shiftKey)
                {
                    scrollProvider.Scroll(ScrollAmount.NoAmount, scrollAmount);
                }
                else if (scrollProvider != null && scrollProvider.VerticallyScrollable && shiftKey)
                {
                    scrollProvider.Scroll(scrollAmount, ScrollAmount.NoAmount);
                }
            }
        }
Example #2
0
        private void InvokeScrollBar(int mouseDelta)
        {
            if (!Focused || mouseDelta == 0)
            {
                return;
            }

            short        mouseNum     = (short)(mouseDelta / 120);
            ScrollAmount scrollAmount = ScrollAmount.NoAmount;

            if (mouseNum < 0)
            {
                //向下滑动
                if (mouseNum >= -2)
                {
                    scrollAmount = ScrollAmount.SmallIncrement;
                }
                else
                {
                    scrollAmount = ScrollAmount.LargeIncrement;
                }
            }
            else if (mouseNum > 0)
            {
                //向上滑动
                if (mouseNum <= 2)
                {
                    scrollAmount = ScrollAmount.SmallDecrement;
                }
                else
                {
                    scrollAmount = ScrollAmount.LargeDecrement;
                }
            }

            if (scrollAmount == ScrollAmount.NoAmount)
            {
                return;
            }

            //修复滚轮滚动Bug

            //取得AutomationPeer
            AutomationPeer automationPeer = FrameworkElementAutomationPeer.FromElement(this);

            if (automationPeer == null)
            {
                automationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(this);
            }
            //得到scroll provider
            IScrollProvider scrollProvider = automationPeer.GetPattern(PatternInterface.Scroll) as IScrollProvider;

            if (scrollProvider != null)
            {
                if (scrollProvider.VerticallyScrollable)
                {
                    scrollProvider.Scroll(ScrollAmount.NoAmount, scrollAmount);
                }
            }
        }
Example #3
0
        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 void ScrollToBottom()
 {
     while (m_scrollProvider.VerticalScrollPercent < 100)
     {
         m_scrollProvider.Scroll(ScrollAmount.NoAmount, ScrollAmount.LargeIncrement);
     }
 }
Example #5
0
        private void UpdateScrollOffset(double delta)
        {
            ScrollAmount verticalScroll = delta < 0.0 ? ScrollAmount.SmallIncrement : ScrollAmount.SmallDecrement;

            for (int i = 0; i < _scrollSize; i++)
            {
                _scrollProvider.Scroll(ScrollAmount.NoAmount, verticalScroll);
            }
        }
Example #6
0
        // 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);
            }
        }
Example #7
0
        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);
            }
        }
Example #8
0
        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);
            }
        }
Example #9
0
        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)
            {
            }
        }
Example #10
0
        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);
            }
        }
Example #11
0
        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);
            }
        }
Example #12
0
            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);
                    }
                }
            }
Example #13
0
        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);
                }
            }
        }
Example #14
0
        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);
                }
            };
        }
Example #15
0
        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 OnPointerMoved(object sender, Touch.PointerEventArgs e)
        {
            if (_currentScrollItem != null)
            {
                double dx = e.Position.X - _lastPosition.X;
                double dy = e.Position.Y - _lastPosition.Y;
                if (!_currentScrollItem.HorizontallyScrollable)
                {
                    dx = 0;
                }
                if (!_currentScrollItem.VerticallyScrollable)
                {
                    dy = 0;
                }

                Windows.UI.Xaml.Automation.ScrollAmount h = Windows.UI.Xaml.Automation.ScrollAmount.NoAmount;
                Windows.UI.Xaml.Automation.ScrollAmount v = Windows.UI.Xaml.Automation.ScrollAmount.NoAmount;
                if (dx < 0)
                {
                    h = Windows.UI.Xaml.Automation.ScrollAmount.SmallIncrement;
                }
                else if (dx > 0)
                {
                    h = Windows.UI.Xaml.Automation.ScrollAmount.SmallDecrement;
                }
                if (dy < 0)
                {
                    v = Windows.UI.Xaml.Automation.ScrollAmount.SmallIncrement;
                }
                else if (dy > 0)
                {
                    v = Windows.UI.Xaml.Automation.ScrollAmount.SmallDecrement;
                }
                _currentScrollItem.Scroll(h, v);
            }

            _lastPosition = e.Position;
        }
Example #19
0
        private void Processor_PointerMoved(object sender, TouchPanels.PointerEventArgs e)
        {
            WriteStatus(e, "Moved");
            if (currentScrollItem != null)
            {
                double dx = e.Position.X - lastPosition.X;
                double dy = e.Position.Y - lastPosition.Y;
                if (!currentScrollItem.HorizontallyScrollable)
                {
                    dx = 0;
                }
                if (!currentScrollItem.VerticallyScrollable)
                {
                    dy = 0;
                }

                Windows.UI.Xaml.Automation.ScrollAmount h = Windows.UI.Xaml.Automation.ScrollAmount.NoAmount;
                Windows.UI.Xaml.Automation.ScrollAmount v = Windows.UI.Xaml.Automation.ScrollAmount.NoAmount;
                if (dx < 0)
                {
                    h = Windows.UI.Xaml.Automation.ScrollAmount.SmallIncrement;
                }
                else if (dx > 0)
                {
                    h = Windows.UI.Xaml.Automation.ScrollAmount.SmallDecrement;
                }
                if (dy < 0)
                {
                    v = Windows.UI.Xaml.Automation.ScrollAmount.SmallIncrement;
                }
                else if (dy > 0)
                {
                    v = Windows.UI.Xaml.Automation.ScrollAmount.SmallDecrement;
                }
                currentScrollItem.Scroll(h, v);
            }
            lastPosition = e.Position;
        }
Example #20
0
 public void Scroll(ScrollAmount horizontalAmount, ScrollAmount verticalAmount)
 {
     _scroller?.Scroll(horizontalAmount, verticalAmount);
 }
Example #21
0
        public void ScrollBarTest()
        {
            IRawElementProviderFragmentRoot provider;
            IRawElementProviderFragment     parent    = null;
            IRawElementProviderFragment     scrollBar = null;
            IRawElementProviderFragment     child     = null;

            ListBox listbox = (ListBox)GetControlInstance();

            listbox.Location = new System.Drawing.Point(3, 3);
            listbox.Size     = new System.Drawing.Size(100, 50);
            provider         = (IRawElementProviderFragmentRoot)GetProviderFromControl(listbox);

            //We should show the ScrollBar
            for (int index = 30; index > 0; index--)
            {
                listbox.Items.Add(string.Format("Element {0}", index));
            }

            //WE DON'T KNOW THE ORDER OF NAVIGATION
            //However we know that we have "somewhere" one Vertical Scrollbar

            bool scrollbarFound = false;

            child = provider.Navigate(NavigateDirection.FirstChild);
            Assert.IsNotNull(child, "FirstChild must not be null");
            int count = 0;

            while (child != null)
            {
                if ((int)child.GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id) == ControlType.ScrollBar.Id &&
                    (OrientationType)child.GetPropertyValue(AutomationElementIdentifiers.OrientationProperty.Id) == OrientationType.Vertical)
                {
                    scrollbarFound = true;
                    scrollBar      = child;
                }

                //ALL elements must have same parent
                parent = child.Navigate(NavigateDirection.Parent);
                Assert.AreEqual(provider, parent, "Parents are different");
                Assert.AreEqual(child.FragmentRoot, parent, "Parents are different (FragmentRoot)");
                child = child.Navigate(NavigateDirection.NextSibling);
                count++;
            }
            //ScrollBar Tests

            Assert.IsTrue(scrollbarFound, "ScrollBar not found");

            int children = 0;

            child = scrollBar.Navigate(NavigateDirection.FirstChild);
            while (child != null)
            {
                parent = child.Navigate(NavigateDirection.Parent);
                Assert.AreEqual(scrollBar, parent, "ScrollBar. Parents are different");
                child = child.Navigate(NavigateDirection.NextSibling);
                children++;
            }

            Assert.AreEqual(5, children, "ScrollBar's children must be 5");


            //Related to bug: https://bugzilla.novell.com/show_bug.cgi?id=414937
            //Get IScrollProvider pattern
            IScrollProvider scrollProvider
                = (IScrollProvider)provider.GetPatternProvider(ScrollPatternIdentifiers.Pattern.Id);

            Assert.IsNotNull(scrollProvider, "We should have a ScrollProvider in ListBox");

            //We only have one vscrollbar, so using the provider shouldn't
            //crash because of missing hscrollbar
            Assert.IsFalse(scrollProvider.HorizontallyScrollable, "We shoudln't have hscrollbar");
            Assert.IsTrue(scrollProvider.VerticallyScrollable, "We should have hscrollbar");

            //Let's move scrollbar
            scrollProvider.Scroll(ScrollAmount.LargeIncrement,
                                  ScrollAmount.LargeIncrement);

            if (scrollProvider.VerticalScrollPercent == 0)
            {
                Assert.Fail("Vertical scroll should move");
            }

            //EOF-Bug

            //Clearing elements should hide scroll and delete all items.
            listbox.Items.Clear();

            child = provider.Navigate(NavigateDirection.FirstChild);
            Assert.IsNull(child, "Shouldn't be any children");

            //This won't add scrollbar
            listbox.Items.Add(1);
            listbox.Items.Add(2);
            child = provider.Navigate(NavigateDirection.FirstChild);
            Assert.IsNotNull(child, "Should be a child");

            //Children MUST BE ListItem
            while (child != null)
            {
                Assert.AreEqual(ControlType.ListItem.Id,
                                child.GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id),
                                "Item should be ListItem");
                child = child.Navigate(NavigateDirection.NextSibling);
            }

            //https://bugzilla.novell.com/show_bug.cgi?id=435103
            listbox.Items.Clear();
            listbox.MultiColumn = true;
            listbox.Items.AddRange(new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 });

            //We need to have two scrollbars
            bool horizontalScrollbar = false;
            bool verticalScrollbar   = false;

            child = provider.Navigate(NavigateDirection.FirstChild);
            while (child != null)
            {
                if ((int)child.GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id)
                    == ControlType.ScrollBar.Id)
                {
                    OrientationType orientation
                        = (OrientationType)child.GetPropertyValue(AutomationElementIdentifiers.OrientationProperty.Id);

                    if (orientation == OrientationType.Horizontal)
                    {
                        horizontalScrollbar = true;
                    }
                    else if (orientation == OrientationType.Vertical)
                    {
                        verticalScrollbar = true;
                    }
                }
                child = child.Navigate(NavigateDirection.NextSibling);
            }
            Assert.IsTrue(horizontalScrollbar, "Missing Horizontal ScrollBar");
            Assert.IsFalse(verticalScrollbar, "Missing Vertical ScrollBar");
        }
Example #22
0
        public void IScrollProviderTest()
        {
            TextBox textBox;
            IRawElementProviderSimple provider;

            GetProviderAndControl(out provider, out textBox);

            textBox.Size = new System.Drawing.Size(30, 30);
            Form.Controls.Add(textBox);
            textBox.ScrollBars = ScrollBars.Both;

            IRawElementProviderFragmentRoot root_prov
                = (IRawElementProviderFragmentRoot)provider;

            // Case #1: Edit with no text
            textBox.Text      = String.Empty;
            textBox.Multiline = false;

            IScrollProvider scroll = provider.GetPatternProvider(
                ScrollPatternIdentifiers.Pattern.Id) as IScrollProvider;

            Assert.IsNull(scroll, "Edit mode with no text incorrectly supports ScrollProvider");

            // Case #2: Edit with large amount of text
            textBox.Text      = TEST_MESSAGE;
            textBox.Multiline = false;

            scroll = provider.GetPatternProvider(
                ScrollPatternIdentifiers.Pattern.Id) as IScrollProvider;
            Assert.IsNull(scroll, "Edit mode with text incorrectly supports ScrollProvider");

            // Case #3: Document with no text
            textBox.Text      = String.Empty;
            textBox.Multiline = true;

            scroll = provider.GetPatternProvider(
                ScrollPatternIdentifiers.Pattern.Id) as IScrollProvider;
            Assert.IsNull(scroll, "Document mode with no text incorrectly supports ScrollProvider");

            // Case #4: Document with large amount of text
            textBox.Text      = TEST_MESSAGE;
            textBox.Multiline = true;

            scroll = provider.GetPatternProvider(
                ScrollPatternIdentifiers.Pattern.Id) as IScrollProvider;
            Assert.IsNotNull(scroll, "Document mode with text doesn't support ScrollProvider");

            // Test that an event is fired when we scroll vertically
            bridge.ResetEventLists();
            scroll.Scroll(ScrollAmount.NoAmount, ScrollAmount.LargeIncrement);
            Assert.AreEqual(1, bridge.AutomationEvents.Count,
                            "EventCount after scrolling vertically");

            // We can't scroll horizontally, so verify that no event is fired
            bridge.ResetEventLists();
            scroll.Scroll(ScrollAmount.LargeIncrement, ScrollAmount.NoAmount);
            Assert.AreEqual(0, bridge.AutomationEvents.Count,
                            "EventCount after scrolling horizontally");

            IRawElementProviderFragment child;

            child = root_prov.Navigate(NavigateDirection.FirstChild);

            Assert.IsNotNull(child, "textBox has no children");
            TestProperty(child, AutomationElementIdentifiers.ControlTypeProperty,
                         ControlType.ScrollBar.Id);

            child = child.Navigate(NavigateDirection.NextSibling);
            Assert.IsNull(child, "textBox has more than one scrollbar");
        }
Example #23
0
 public void Scroll(ScrollAmount horizontalAmount, ScrollAmount verticalAmount)
 {
     provider.Scroll(horizontalAmount, verticalAmount);
 }
Example #24
0
        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;
            }
        }