views:

159

answers:

2

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);
        }
    }
}
A: 

Hey Brian,

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

LBugnion
Good suggestion, Laurent. I tried that, but I still never get the TouchMove event. I've tried overriding the OnTouchMove as well... but it never sets "Handled" to true in the base... blerg.
Brian Genisio
I'm new at the touch gesture stuff; would you have to register an event handler once you have a TouchDown event? Or does the system depend on certain hardware to fire TouchMove, which you may not have? Just guesses.
Rob Perkins
When the slider is not in a scroll viewer, everything works properly because the touch events get translated to mouse events. I can even get the TouchMove event without the scroll viewer. BUT, once the scroll viewer takes over, it doesn't let the TouchMove event get down, so it never gets the chance to get translated as a Mouse move.
Brian Genisio
A: 

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.

Rob Perkins
As far as I can tell, the "Handled" flag never gets set to True for PreviewTouchMove OR TouchMove. Still, the events never make their way down to the slider. TouchDown DOES, however, make it down. I've tried CaptureTouch when this happens... but still no luck :(
Brian Genisio