Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
585
Create button that scrolls on mousedown and stops on mouseup
posted

I wish to create two buttons which will appear next to the editor.

On one button whilst the mousedown I wish to scroll the richtexteditor down. On MouseUp it will stop scrolling.

I then wish for another button to do the same thing but scroll the richtexteditor Up.


Thanks for any instance.

Dave

Parents
  • 1560
    Offline posted

    Hello,

    I have been looking into your requirement and created a small sample with XamRichTextEditor and two buttons Up/Down.

    In order to get the vertical scrollbar and be able to modify it on button click or any other event you could use the following code:

    var scrollBar = Utilities.GetDescendantFromType((this.xrte1), typeof(ScrollBar), true) as ScrollBar;

    After that you could change the scroll bar value using its Value property:

    void scrolling (ScrollBar scrollBar, string direction)
    {
         if(direction == "up")
         {
             while (true)
             {
                 this.Dispatcher.Invoke((Action)(() =>
                {
                    scrollBar.Value -= scrollBar.SmallChange;
                 }));
               Thread.Sleep(300);
              }
         }
       else
       {
            while (true)
           {
                this.Dispatcher.Invoke((Action)(() =>
                {
                   scrollBar.Value += scrollBar.SmallChange;
                }));
               Thread.Sleep(300);
            }
       }
    }

    In order to keep scrolling till the mouse is up, I'm using a thread that would start and call the scrolling method until it is aborted in the button PreviewMouseUp event handler.

    I have attached my sample below. Please test it on your side and let me know if I may be of any further assistance.

    Sincerely,

    Teodosia Hristodorova

    Associate Software Developer

    5415.XamRichTextEditor_scroll_buttons.zip

Reply Children