ScrollViewer Multiplexer Eats Touch Events

WPF 4.0:

I have a scroll viewer with many sliders inside it. I want the scroll viewer to swing with the touch, and I want the internal slider to also respond to the touch.

Unfortunately, the scroll viewer eats the "TouchMove" events and does not pass them to the slider. 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 is:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = Items;
    }

    public IEnumerable<int> Items
    {
        get
        {
            return Enumerable.Range(0, 50);
        }
    }
}
+3
source share
4 answers

See my answer to this question: ScrollViewer in touch interface not working properly

, Thumb - , .

+2

" , ". AddHandler "handledEventsToo" true?

Cheers, Laurent

0

TouchMove, . (PreviewTouchMove ..), . , .

0
source

You can try to create your own class derived from ScrollViewer and override the OnTouchMove method.

public class CustomScrollViewer : System.Windows.Controls.ScrollViewer
{
    protected override void OnTouchMove(System.Windows.Input.TouchEventArgs e)
    {
        // delete the base.OnTouchMove() call to prevent event being "eat" :)
    }
}

Then you edit xaml as follows:

<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>
                    <local:CustomScrollViewer VerticalScrollBarVisibility="Auto" PanningMode="Both" >
                        <ItemsPresenter />
                    </local:CustomScrollViewer>
                </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>
0
source

Source: https://habr.com/ru/post/1754865/


All Articles