tom.maruska
tom.maruska

Reputation: 1481

WPF - Moving window using manipulation event causes window flickering

I'm trying to move window on touch devices. I want to use manipulation events, because I'm planning use also inertion.

Problem is, that when I try to move window to left or right, windows starts to flickering (which is caused by manipulation delta events, see later).

I was able to reproduce behavior into following example:

<Window x:Class="MultiTouchTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow"
    Width="525"
    Height="350"
    IsManipulationEnabled="True"
    ManipulationDelta="UIElement_OnManipulationDelta"
    WindowStyle="None" />

code behind:

public partial class MainWindow
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void UIElement_OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        Debug.WriteLine(e.DeltaManipulation.Translation.X);
        Left += e.DeltaManipulation.Translation.X;
        e.Handled = true;
    }
}

and output from WriteLine() is:

3
-3
3
-3
3
-3
3
-3
...

Does anybody know how to achieve window moving using manipulation events?

Upvotes: 0

Views: 671

Answers (1)

dirk
dirk

Reputation: 1

in the case you change the Left property of the, the OnManipulationDelta event is fired another one with the new opposite value of "e.DeltaManipulation.Translation.X". Unfortunately switching off the event during changing the Left property does not help. Try to use the following code:

`

public partial class MainWindow
{
    bool mCausedByCode = false;

    public MainWindow()
    {
        InitializeComponent();
    }

    private void UIElement_OnManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        Debug.WriteLine(e.DeltaManipulation.Translation.X);
        if(!mCausedByCode)
        {
            Left += e.DeltaManipulation.Translation.X;
            mCausedByCode = true;
        }
        else
        {
            mCausedByCode = false;
        }
        e.Handled = true;
    }
}

`

I tried it on my PC and it helped.

Upvotes: 0

Related Questions