Thank you @Anonymous for the update but it did not move the rectangle.
I found the solution after analyzing the code and playing around a little. Initially I was using the manipulation events to implement the drag and drop behavior for the dynamic rectangle. The issue was, I had to override the OnPointerPressed, OnPointerReleased & OnPointerMoved events in the code to obtain some other functionalities of the application. I have not handled the rectangle manipulation events from the base pointer events so it was always ended up executing the base pointer events.
Here is the xaml code
<Grid x:Name="viewport">
<Border x:Name="viewportBorder" Background="White" BorderThickness="15, 15, 15, 15" BorderBrush="#FF353334" />
</Grid>
Here is the code behind,
private bool TransformInProgress = false;
private bool TransformStarted = false;
protected override void OnPointerMoved(PointerRoutedEventArgs e)
{
...
if (TransformInProgress)
{
Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.SizeAll, 0);
return;
}
...
base.OnPointerMoved(e);
}
protected override void OnPointerPressed(PointerRoutedEventArgs e)
{
...
if (TransformInProgress && TransformHandlerAvailableAtCurrentApoint(currentPointerLocation))
return;
else
{
TransformInProgress = false;
TransformStarted = false;
}
if (TransformInProgress && commentIndexAtCurrentPoint == -1)
{
ClearTransformHandles();
return;
}
...
base.OnPointerPressed(e);
}
protected override void OnPointerReleased(PointerRoutedEventArgs e)
{
if (TransformInProgress && TransformStarted)
return;
...
base.OnPointerReleased(e);
}
private void AttachRectangleMoveHandler(Point point)
{
var handler = new Rectangle
{
Width = 14,
Height = 14,
Fill = new SolidColorBrush(Colors.Gray),
CompositeMode = ElementCompositeMode.SourceOver,
Name = "RectangleTransformHandler",
ManipulationMode = ManipulationModes.All,
RenderTransformOrigin = new Point(point.X - 7d, point.Y - 7d),
RenderTransform = new TranslateTransform { X = point.X - 7d, Y = point.Y - 7d }
};
handler.ManipulationStarting += delegate (object sender, ManipulationStartingRoutedEventArgs e) { TransformStarted = true; };
handler.ManipulationDelta += Handler_ManipulationDelta;
handler.ManipulationCompleted += delegate (object sender, ManipulationCompletedRoutedEventArgs e) { TransformStarted = false; };
handler.PointerEntered += delegate (object sender, PointerRoutedEventArgs e) { TransformInProgress = true; };
handler.PointerExited += delegate (object sender, PointerRoutedEventArgs e) { Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.Arrow, 0); };
SelectCanvas.Children.Add(handler);
}