WPF:从的ScrollViewer滚动条获取事件 [英] WPF: Get an event on the scrollbar from Scrollviewer
问题描述
我想只得到,如果我的用户向左或向右拖动滚动条的事件。
当我用鼠标点击事件,它包含了整个画布太..
我发现有一个事件处理程序ScrollChanged但是这不是我真正想要什么,因为我的画布宽度增加每秒10和事业10每秒事件ScrollChanged倍。
我只想用鼠标
draging滚动条得到一个事件
<的ScrollViewer X:NAME =coordinateScrollVerticalScrollBarVisibility =自动HorizontalScrollBarVisibility =自动保证金=75,0,0,0WIDTH =1125HEIGHT =750背景=透明滚轮=coordinateSystemBackground_MouseWheelMouseDoubleClick =coordinateScroll_MouseDoubleClickScrollChanged =coordinateScroll_ScrollChanged>
<帆布X:NAME =coordinateSystem的HorizontalAlignment =左VerticalAlignment =评出的光标=十字UseLayoutRounding =FALSEWIDTH =1125HEIGHT =720背景=透明滚轮=coordinateSystemBackground_MouseWheel>
< /帆布>
< /&的ScrollViewer GT;
从我如何理解你,你试图每当用户拖动左边或右边的滚动条来访问的ScrollViewer
。为了做到这一点,使用的的ScrollViewer
的 ScrollChanged
事件。在事件处理程序,你有你的发件人
和电子
参数。要访问的ScrollViewer
,简单地把发件人属性
为的ScrollViewer
是这样的:
的ScrollViewer currentViewer =(ScrollViewer中)发送;
这应该允许您访问所有关于的ScrollViewer $信息C $ C>。
如果您遇到与画布烧成ScrollChanged事件的宽度的问题,然后把支票在事件处理程序,看是否事件即将从小鼠,或从画布宽度变化
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>
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.
这篇关于WPF:从的ScrollViewer滚动条获取事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!