Moving Thumb x and y

BitSmithy 2,141 Reputation points
2020-04-20T17:09:11.327+00:00

Hello,

When I set Thumb.ManipulationMode="TranslateX" - I can move it on Canvas X axis
When I set Thumb.ManipulationMode="TranslateY" - I can move it on Canvas Y axis

How to set Thumb.ManipulationMode to move it on Canvas X and Y axses.

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

Accepted answer
  1. Richard Zhang-MSFT 6,936 Reputation points
    2020-04-21T01:38:43.51+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    If you need to allow the control to move on the X axis and Y axis at the same time, you can set:

    ManipulationMode="All"

    This is a sample code that might show this process:

    xaml

    <Canvas Width="500" Height="500" Background="White">
        <Thumb ManipulationMode="All" Width="50" Height="50" Background="Red" ManipulationDelta="Thumb_ManipulationDelta">
            <Thumb.RenderTransform>
                <TranslateTransform x:Name="dragTranslation"></TranslateTransform>
            </Thumb.RenderTransform>
        </Thumb>
    </Canvas>
    

    xaml.cs

    private void Thumb_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        Thumb thumb = sender as Thumb;
        if (thumb == null)
        {
            return;
        }
    
        if (dragTranslation == null)
        {
            dragTranslation = new TranslateTransform();
        }
    
        thumb.RenderTransform = dragTranslation;
    
        dragTranslation.X += e.Delta.Translation.X;
        dragTranslation.Y += e.Delta.Translation.Y;
    }
    

    Thanks.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.