Wednesday, January 27, 2010

.net 4.0, wpf 4 Translation Transform Flickering. Solution.

Translation manipulation not working.?

TranslateTransform issue in wpf 4.0.

There is an issue with DeltaManipulation in .net 4.0 (Till RC 1).

e.DeltaManipulation behaves weired it always returns unexpected values.

But the issue is only with e.DeltaManipulation but not with e.ManipulationOrigin and e.CumulativeManipulation.
With the Cumalative manipulation or with manipulation orgin we can easily get the delta manipulation value.
while starting manipulation take the start position and subtract the value from the Cumalativemanipulation. we will get delta value.

Here is the the sample Code using C#















using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;

namespace ManipulationSample
{
///
/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow : Window
{
MatrixTransform tg = new MatrixTransform();
public MainWindow()
{
InitializeComponent();
Img.RenderTransform = tg;
}
Point StartPosition = new Point();
private void Canvas_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
StartPosition = e.ManipulationOrigin;
Debug.WriteLine("StartPosition::::::: " + StartPosition);
}

private void Canvas_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
e.ManipulationContainer = Img;
}

private void Canvas_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{

var matrix = ((MatrixTransform)Img.RenderTransform).Matrix;
matrix.Translate((e.ManipulationOrigin.X - StartPosition.X), (e.ManipulationOrigin.Y - StartPosition.Y));
((MatrixTransform)Img.RenderTransform).Matrix = matrix;
}
}
}