Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8494645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:21:26+00:00 2026-06-10T23:21:26+00:00

I am aiming to build a ScrollViewer type of control which holds an array

  • 0

I am aiming to build a ScrollViewer type of control which holds an array of buttons.
The application using this scrollviewer control will be installed on touchscreen terminals.
The terminals will more than likely be running windows XP.

I want the user to be able to use their finger to scroll through the buttons horizontally when there are more buttons than will fit the viewable area. Note that I dont want to display any scrollbars.

Ive learned that the ‘PanningMode’ property cannot be used with windows xp but only windows 7 where the touchscreen terminal supports ‘Windows Touch’.

Using WPF I have built a screen which includes a scrollViewer control which in turn has a collection of buttons. I did manage to create a panning effect by overriding the windows previewMouseDown, previewMouseMove events but this creates a problem whereby the Operating System does not know if the user has pressed the scrollviewer to select a buton or touched the scrollviewer with the intention of scrolling. Basically the override method will always win and left button pressed will be true.

So i need a way to be able to scroll but still maintain the ability to click(touch) a button within the scrollviewer.

I will attach my sample code below.

If there is a possible way to do this I would be delghted to hear it 🙂 OR!! even if there is such a control out there available to purchase I would also be interested in that.

many thanks!

XAML:

 <Grid x:Name="LayoutSelector" Grid.Column="0" Grid.Row="1"  DataContext="{Binding Main, Source={StaticResource MainVM}}" Height="100" >
                        <ScrollViewer x:Name="ScrollViewer" Width="Auto" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" PanningMode="HorizontalOnly" >
                            <!--<ItemsControl ItemsSource="{Binding SelectedLayout}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <WrapPanel HorizontalAlignment="Left" Height="100" />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>-->
                            <StackPanel CanHorizontallyScroll="True" Orientation="Horizontal">
                                <Button x:Name="Test1" Content="Button1" Width="150"/>
                                <Button x:Name="Test2" Content="Button1" Width="150"/>
                                <Button x:Name="Test3" Content="Button1" Width="150"/>
                                <Button x:Name="Test4" Content="Button1" Width="150"/>
                                <Button x:Name="Test5" Content="Button1" Width="150"/>
                                <Button x:Name="Test6" Content="Button1" Width="150"/>
                                <Button x:Name="Test7" Content="Button1" Width="150"/>
                                <Button x:Name="Test8" Content="Button1" Width="150"/>
                                <Button x:Name="Test9" Content="Button1" Width="150"/>
                                <Button x:Name="Test10" Content="Button1" Width="150"/>
                                <Button x:Name="Test11" Content="Button1" Width="150"/>
                                <Button x:Name="Test12" Content="Button1" Width="150"/>
                            </StackPanel>


                        </ScrollViewer>
                    </Grid>

c#:

using System;
using System.Globalization;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media.Effects;
using ViewModels;

namespace Views
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    private Point scrollStartPoint;
    private Point scrollStartOffset;

    public MainWindow()
    {
        InitializeComponent();
        Closing += (s, e) => ViewModelCreator.Cleanup();
    }

    protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
    {
        if (ScrollViewer.IsMouseOver)
        {
            // Save starting point, used later when determining 
            //how much to scroll.
            scrollStartPoint = e.GetPosition(this);
            scrollStartOffset.X = ScrollViewer.HorizontalOffset;
            scrollStartOffset.Y = ScrollViewer.VerticalOffset;

            // Update the cursor if can scroll or not.
            this.Cursor = (ScrollViewer.ExtentWidth >
               ScrollViewer.ViewportWidth) ||
                (ScrollViewer.ExtentHeight >
                ScrollViewer.ViewportHeight) ?
               Cursors.ScrollAll : Cursors.Arrow;

            this.CaptureMouse();
        }

        base.OnPreviewMouseDown(e);
    }

    protected override void OnPreviewMouseMove(MouseEventArgs e)
    {
            //if (this.IsMouseCaptured)
            //{
                // Get the new scroll position.
                Point point = e.GetPosition(this);

                // Determine the new amount to scroll.
                Point delta = new Point(
                    (point.X > this.scrollStartPoint.X) ?
                        -(point.X - this.scrollStartPoint.X) :
                        (this.scrollStartPoint.X - point.X),

                    (point.Y > this.scrollStartPoint.Y) ?
                        -(point.Y - this.scrollStartPoint.Y) :
                        (this.scrollStartPoint.Y - point.Y));

                // Scroll to the new position.
                ScrollViewer.ScrollToHorizontalOffset(
                    this.scrollStartOffset.X + delta.X);
                ScrollViewer.ScrollToVerticalOffset(
                    this.scrollStartOffset.Y + delta.Y);
            //}

        base.OnPreviewMouseMove(e);
    }

    protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
    {
        if (this.IsMouseCaptured)
        {
            this.Cursor = System.Windows.Input.Cursors.Arrow;
            this.ReleaseMouseCapture();
        }

        base.OnPreviewMouseUp(e);
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:21:28+00:00Added an answer on June 10, 2026 at 11:21 pm

    Ok so after many more hours of fiddling and trial and error it occurred to me that the click event which was what I was wanting to maintain funcionality for was not possible because the mouseCapture event was executed and holding the mouse preventing from any further action taking place, except for the ‘PreviewMouseUp’ event which released the mouse when I left clicked.

    So what I did was to capture the mouse position on entering or hovering over the scrollviewer and then overriding the ‘OnPreviewMouseMove’ method for the window to get the new position. The important thing was in the ‘MouseEnter’ event ( Not overridden ) I am not capturing the mouse therefor the mouse is still allowed to click the buttons contained in the scrollviewer!!

    Code shown below!

    C#

    using System;
    using System.Globalization;
    using System.Threading;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Markup;
    using System.Windows.Media.Effects;
    using ViewModels;
    
    namespace Views
    {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Point scrollStartPoint;
        private Point scrollStartOffset;
    
        public MainWindow()
        {
            InitializeComponent();
            Closing += (s, e) => ViewModelCreator.Cleanup();
        }
    
        //protected void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
        //{
        //    if (ScrollViewer.IsMouseOver)
        //    {
        //        // Save starting point, used later when determining 
        //        //how much to scroll.
        //        scrollStartPoint = e.GetPosition(this);
        //        scrollStartOffset.X = ScrollViewer.HorizontalOffset;
        //        scrollStartOffset.Y = ScrollViewer.VerticalOffset;
    
        //        // Update the cursor if can scroll or not.
        //        this.Cursor = (ScrollViewer.ExtentWidth >
        //           ScrollViewer.ViewportWidth) ||
        //            (ScrollViewer.ExtentHeight >
        //            ScrollViewer.ViewportHeight) ?
        //           Cursors.ScrollAll : Cursors.Arrow;
    
        //        this.CaptureMouse();
        //    }
    
        //    base.OnPreviewMouseDown(e);
        //}
    
        protected override void OnPreviewMouseMove(MouseEventArgs e)
        {
            if (ScrollViewer.IsMouseOver)
            {
                // Get the new scroll position.
                Point point = e.GetPosition(this);
    
                // Determine the new amount to scroll.
                Point delta = new Point(
                    (point.X > this.scrollStartPoint.X) ?
                        -(point.X - this.scrollStartPoint.X) :
                        (this.scrollStartPoint.X - point.X),
    
                    (point.Y > this.scrollStartPoint.Y) ?
                        -(point.Y - this.scrollStartPoint.Y) :
                        (this.scrollStartPoint.Y - point.Y));
    
                // Scroll to the new position.
                ScrollViewer.ScrollToHorizontalOffset(
                    this.scrollStartOffset.X + delta.X);
                ScrollViewer.ScrollToVerticalOffset(
                    this.scrollStartOffset.Y + delta.Y);
            }
    
            base.OnPreviewMouseMove(e);
        }
    
        private void ScrollViewer_MouseEnter(object sender, MouseEventArgs e)
        {
            if (ScrollViewer.IsMouseOver)
            {
                // Save starting point, used later when determining 
                //how much to scroll.
                scrollStartPoint = e.GetPosition(this);
                scrollStartOffset.X = ScrollViewer.HorizontalOffset;
                scrollStartOffset.Y = ScrollViewer.VerticalOffset;
    
                // Update the cursor if can scroll or not.
                this.Cursor = (ScrollViewer.ExtentWidth >
                   ScrollViewer.ViewportWidth) ||
                    (ScrollViewer.ExtentHeight >
                    ScrollViewer.ViewportHeight) ?
                   Cursors.Arrow : Cursors.Arrow;
            }
        }
    }
    }
    

    XAML:

                 <Grid x:Name="LayoutSelector" Grid.Column="0" Grid.Row="1"  DataContext="{Binding Main, Source={StaticResource MainVM}}" Height="100" >
                            <ScrollViewer x:Name="ScrollViewer" Width="Auto" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" PanningMode="HorizontalOnly"
                                          MouseEnter="ScrollViewer_MouseEnter"  >
                                <ItemsControl ItemsSource="{Binding SelectedLayout}">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <WrapPanel HorizontalAlignment="Left" Height="100" />
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                </ItemsControl>
    
                            </ScrollViewer>
                        </Grid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm aiming to build up a JSON array of mouse positions and pass them
I am using C in Fedora Linux to build a voice streaming application. I
I am aiming to build a site that will contain a lot of user
I currently have an application which will drop pins onto various points of interest
I am aiming to create a .bat launcher that will execute a command line
I'm aiming to write an application for galaxy tab and decide to use platform
I am aiming to create an app which receives an NSString, like A12EE345, then
I'm building an interpreter and as I'm aiming for raw speed this time, every
i'm aiming to put 2 search forms on the same wordpress page. i'm using
This is what I am aiming to do... vector < pair<vector<int>,int> > var_name (x,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.