Scrollviewer和自定义滑块 [英] Scrollviewer and custom slider
问题描述
大家好,
所以我有一个自定义控件就像一个年份和月份的滑块一样,用户只需向上和向下滑动标签即可选择所需的月份/ year。
So I have a custom control which works like a slider with year and month, the user simply slides the tabs up and down to choose the desired month/year.
控件包含在stackpanel和ScrollViewer中:
The control is wrapped in a stackpanel and ScrollViewer:
<ScrollViewer x:Name="periodScroll" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Grid.Column="1" DragLeave="periodScroll_DragLeave">
<StackPanel x:Name="wrapper" Grid.Row="0" Background="{Binding Background, ElementName=MainPivot}">
<Slider:RangeSlider x:Name="MonthSelector" Grid.Row="0" Width="790" Thumb.DragCompleted="MonthSelector_DragCompleted" HorizontalAlignment="Right" ScrollViewer.CanContentScroll="True" />
</StackPanel>
</ScrollViewer>
当用户拖动滑块超出可见范围时,我想允许滚动查看器移动,有人能帮忙吗?
I want to allow the scrollviewer to move when user drags the slider outside of the visible range, would anyone be able to help?
非常感谢,
Joe
推荐答案
您好JoeyStyles,
Hi JoeyStyles,
我们可以使用ScrollToHorizontalOffset以编程方式移动scrollviewer。这是一个简单的示例供您参考。
We could use ScrollToHorizontalOffset to move scrollviewer programmatically. here is a simple sample for your reference.
#Xaml
#Xaml
<StackPanel x:Name="wrapper" Grid.Row="0" Background="{Binding Background, ElementName=MainPivot}">
<Slider Margin="0,50,0,0" x:Name="MonthSelector" Grid.Row="0" Width="790"
Thumb.DragCompleted="MonthSelector_DragCompleted"
Thumb.DragDelta="MonthSelector_DragDelta"
HorizontalAlignment="Right"
ScrollViewer.CanContentScroll="True" />
</StackPanel>
#Code Behind
#Code Behind
private void MonthSelector_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
periodScroll.ScrollToHorizontalOffset(((double)this.MonthSelector.Value)*50);
}
祝你好运,
张龙
这篇关于Scrollviewer和自定义滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!