Drag and drop Image UserControl in a Metro App?

Answered Drag and drop Image UserControl in a Metro App?

  • 2012年3月7日 上午 07:44
     
     

    Hi,

    I have an image control in a xaml file:

    <Image x:Name="myImage" />

    I need to be able to drag the image around in my view at runtime. How do I go about doing this?

    Thanks much.


    V

所有回覆

  • 2012年3月7日 上午 10:40
     
     已答覆 包含代碼
            <Image x:Name="myImage"
                   Source="Assets/Logo.png"
                   Stretch="None"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center"
                   ManipulationMode="All"
                   ManipulationDelta="myImage_ManipulationDelta_1">
                <Image.RenderTransform>
                    <CompositeTransform />
                </Image.RenderTransform>
            </Image>
    

    and the event handler

            private void myImage_ManipulationDelta_1(object sender, ManipulationDeltaRoutedEventArgs e)
            {
                var ct = (CompositeTransform)myImage.RenderTransform;
                ct.TranslateX += e.Delta.Translation.X;
                ct.TranslateY += e.Delta.Translation.Y;
            }
    


    http://babaandthepigman.spaces.live.com/blog/

  • 2012年5月19日 上午 09:39
     
     

    Hi,

        How Can i get drag  and drop released (finished) event ? in order to callback 


    Grant 


    • 已編輯 Tsingbegin 2012年5月19日 上午 09:42
    •  
  • 2012年5月19日 下午 07:00
     
     提議的解答

    For XAML in Windows 8 the Drag and drop related events only fire when you start a Drag action from a ListView or GridView. If you are just performing your own drag such as you are doing, you will have to rely on listening to pointer events to determine when the drag is "done".

    thanks,
    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"
  • 2012年7月22日 下午 06:54
     
     
    Or take a look at PanView, discussed in this thread.

    John Michael Hauck

  • 2013年4月17日 上午 10:09
     
     
    Thanks for the code , is there a way to test whether the picture that we're moving is in a specific place or not please