c# - limit image movement inside canvas -


Application in Window 8, I am dragging an image inside the canvas. I want to force that image inside the canvas? How can I do this

Here is my code:

XAML

; Canvas X: name = "canvas1" Grid.Row = "0" grid. Column = "0" grid = "0" grid. Colspan = "2" grid. Rowspan = "2" background = "white" & gt; & Lt; Image X: Name = "Image1" height = "100" width = "100" margin = "0" HorizontalAlignment = "left" ManipulationDelta = "Image_ManipulationDelta_1" ManipulationMode = "All" & gt; & Lt; Image.RenderTransform & gt; & Lt; CompositeTransform / & gt; & Lt; /Image.RenderTransform> & Lt; / Image & gt; & Lt; / Canvas & gt; ` 

C #

  Private Zero Image_ManipulationDelta_1 (Object Sender, ManipulationDeltaRoutedEventArgs E) {var imag = (CompositeTransform) image1.RenderTransform; Imag.TranslateX + = e.Delta.Translation.X; Image.TranslateY + = e.Delta.Translation.Y;}  

you already have The only code is:

  Composite transformer imgTrans = image1.TransformToVisual (canvas 1); Windows. Foundation. Point IMGpoint = IMGtrance TransSense Point (new Windows Foundation. Point); Var isch = (composite conversion) image1. Render Transform; If (imgPoint.X  

Comments