如何在动态创建的图像上添加拖放行为

时间:2014-04-07 15:49:07

标签: windows-phone-8

我正在开发一个Windows Phone 8应用程序,其中我动态地在画布上创建了一些图像。现在我想在每个动态创建的图像上添加拖放行为。

private void btnStart_Click(object sender, RoutedEventArgs e)
{      
    Image img = new Image();
    img.Stretch = Stretch.Uniform;
    img.Name = imgDefaultName + ctr.ToString();
    img.Height = 220;
    img.Width = 160;

    MyCanvas.Children.Add(img);
    Canvas.SetLeft(img, left);
    Canvas.SetTop(img, top);
    img.Source = new BitmapImage(new Uri("/Assets/eclipse.png", UriKind.Relative));

    // left = left + 100;

}

我的xaml看起来像这样

 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,5,0,0">
     <!--<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible">-->
         <Canvas Name="MyCanvas" Background="WhiteSmoke" Width="483">
         </Canvas>
     <!--</ScrollViewer>-->
 </Grid>

1 个答案:

答案 0 :(得分:0)

您必须处理图片的UIElement.ManipulationStartedUIElement.ManipulationDeltaUIElement.ManipulationCompleted事件。

检查THIS示例。