2

I want get an event only if I the user drag the scrollbar left or right.

When I use a MouseClick event, it contains the whole canvas too...

I found that there is an Event Handler "ScrollChanged" but this is not really what I want because the width of my canvas grow every second by 10 and that cause 10 times per second the event ScrollChanged.

I want just get an event by draging the scrollbar with the mouse

        <ScrollViewer x:Name="coordinateScroll" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Margin="75,0,0,0" Width="1125" Height="750" Background="Transparent" MouseWheel="coordinateSystemBackground_MouseWheel" MouseDoubleClick="coordinateScroll_MouseDoubleClick " ScrollChanged="coordinateScroll_ScrollChanged" >
            <Canvas x:Name="coordinateSystem" HorizontalAlignment="Left" VerticalAlignment="Top" Cursor="Cross" UseLayoutRounding="False"  Width="1125" Height="720" Background="Transparent" MouseWheel="coordinateSystemBackground_MouseWheel" >

            </Canvas>
        </ScrollViewer>
7
  • 2
    What do you mean you just want to get the Scrollbar? The documentation for the ScrollChanged event sounds exactly like what you're looking for: msdn.microsoft.com/en-us/library/… Commented Jun 6, 2013 at 13:12
  • Can I get it only by clicking by mouse ? Commented Jun 6, 2013 at 13:14
  • What are you trying to "get"? Commented Jun 6, 2013 at 13:14
  • An event by clicking on the scrollbar Commented Jun 6, 2013 at 13:18
  • You're asking for two different things. Do you want the event when the user drags the scrollbar, or when they just click on the scrollbar? Commented Jun 6, 2013 at 13:20

1 Answer 1

1

From how I'm understanding you, you're trying to access the ScrollViewer whenever the user drags the scrollbar left or right. In order to do this, use the ScrollChanged event of the ScrollViewer. In the event handler, you'll have your sender and e arguments. To access properties of the ScrollViewer, simply cast sender as a ScrollViewer like this:

ScrollViewer currentViewer = (ScrollViewer)sender;

That should allow you to access all the information about the ScrollViewer.

If you're having a problem with the width of the Canvas firing the ScrollChanged event, then put a check in the event handler to see if the event is coming from a mouse, or from the Canvas width changing.

Sign up to request clarification or add additional context in comments.

2 Comments

But how get I the event ? For example: The user is draging the scrollbar to left and then an event is shows up and in this Event I want get the actual posiotion of my scrollbar
I just edited my answer, and I think it should solve your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.