コード例 #1
0
        void SelectionRect_ManipulationDelta(object sender, Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e)
        {
            // Get current position of selection's bounding box
            var curPos = new Windows.Foundation.Point(
                Windows.UI.Xaml.Controls.Canvas.GetLeft(SelectionRect),
                Windows.UI.Xaml.Controls.Canvas.GetTop(SelectionRect)
                );

            // Compute new position, making sure that the bounding box does not go outside the InkingArea
            var newPos = new Windows.Foundation.Point(
                Math.Max(0, Math.Min(curPos.X + e.Delta.Translation.X, InkingArea.ActualWidth - SelectionRect.Width)),
                Math.Max(0, Math.Min(curPos.Y + e.Delta.Translation.Y, InkingArea.ActualHeight - SelectionRect.Height))
                );

            // Compute the actual translation to pass to InkManager.MoveSelected
            var translation = new Windows.Foundation.Point(
                newPos.X - curPos.X,
                newPos.Y - curPos.Y
                );

            if (Math.Abs(translation.X) > 0 || Math.Abs(translation.Y) > 0)
            {
                // Move the selection's bounding box
                Windows.UI.Xaml.Controls.Canvas.SetLeft(SelectionRect, newPos.X);
                Windows.UI.Xaml.Controls.Canvas.SetTop(SelectionRect, newPos.Y);

                // Move selected ink
                inkManager.MoveSelected(translation);

                // Re-render everything
                renderer.Clear();
                renderer.AddInk(inkManager.GetStrokes());
                renderer.UpdateSelection();
            }

            e.Handled = true;
        }