多点触摸ScrollViewer吃触摸事件
WPF 4.0:
我有滚动查看器,其中有许多滑块。我希望滚动查看器能够通过触摸进行平移,并且希望内部滑块也能够响应触摸。
不幸的是,滚动查看器正在吃掉“TouchMove”事件,而不是将它们传递给滑块控件。知道如何解决这个问题吗?
这是我的 XAML:
<Window x:Class="ScrollingTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer VerticalScrollBarVisibility="Auto" PanningMode="Both" >
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Height="100" BorderThickness="2" BorderBrush="Black">
<Slider Value="{Binding ., Mode=TwoWay}" Width="300" Minimum="0" Maximum="100" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Window>
和我的代码隐藏:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = Items;
}
public IEnumerable<int> Items
{
get
{
return Enumerable.Range(0, 50);
}
}
}
WPF 4.0:
I have scroll viewer with many Sliders inside of it. I want the scroll viewer to pan with touch, and I want the internal slider to also respond to touch.
Unfortunately, the scroll viewer is eating the "TouchMove" events and not passing them down to the slider control. Any idea how to fix this?
Here is my XAML:
<Window x:Class="ScrollingTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer VerticalScrollBarVisibility="Auto" PanningMode="Both" >
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Height="100" BorderThickness="2" BorderBrush="Black">
<Slider Value="{Binding ., Mode=TwoWay}" Width="300" Minimum="0" Maximum="100" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Window>
And my Code-behind:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = Items;
}
public IEnumerable<int> Items
{
get
{
return Enumerable.Range(0, 50);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请参阅我对此问题的回答: ScrollViewer触摸界面无法正常工作
我刚刚在我们的应用程序中解决了这个问题,并使用自定义 Thumb 控件 - 在我的回答中,我解释了导致问题的原因。
Please see my answer to this question: ScrollViewer in a touch interface not working properly
I just resolved this issue in our app as well using a custom Thumb control - in my answer I explain what is causing the problem.
这听起来像是“路由事件标记为已处理”的情况。您可以尝试使用 AddHandler 订阅该事件,并将最后一个参数“handledEventsToo”设置为 true 吗?
干杯,
洛朗
This sounds like a case of "routed event marked as handled". Can you try using AddHandler to subscribe to that event, and set the last parameter "handledEventsToo" to true?
Cheers,
Laurent
它很可能正在处理 TouchMove 事件。您可以在 Slider 控件中处理冒泡事件(PreviewTouchMove 等)。您需要协调触摸事件的处理方式。
It's handling the TouchMove event, most likely. There are bubbling events (PreviewTouchMove, etc) you could handle in your Slider control. You would need to coordinate how you want the touch events to be handled.
您可以尝试创建自定义类,从 ScrollViewer 派生并重写 OnTouchMove 方法。
然后,您可以像这样编辑 xaml:
You can try to make your custom class, derived from ScrollViewer and override OnTouchMove method.
Then, you edit the xaml like this: