在xaml窗口商店应用中在画布上拖动多个图像?

时间:2014-05-13 18:07:10

标签: c# xaml windows-store-apps windows-8.1

我想在画布上拖动多个图像。我在画布中有一个图像,它有ManipulationDelta事件来拖动图像

void MainPage_Loaded(object sender, RoutedEventArgs e)
{       
    DragableItem.ManipulationDelta += DragableItem_ManipulationDelta;
    DragableItem.RenderTransform = new TranslateTransform();
}


void DragableItem_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    var translate = (TranslateTransform)DragableItem.RenderTransform;
     translateTransform.X += e.Delta.Translation.X;
                translateTransform.Y += e.Delta.Translation.Y;
}

它的工作正常,但是当我在按钮上创建运行时图像时,点击这样

private void Button_Click(object sender, RoutedEventArgs e)
{
    Image image = new Image();
    string url = "ms-appx:///Assets/992829_484663934955807_859212711_n.jpg";
    BitmapImage bm = new BitmapImage();

    bm.UriSource = new Uri(url, UriKind.Absolute);
    image.Source = bm;
    image.Height = 100;
    image.Width = 100;

    image.Name = "img" + i++;
    image.ManipulationDelta+=Drag;
    DrawCanvas.Children.Add(image);

}

和像这样称为拖动的同一事件

private void Drag(object sender, ManipulationDeltaRoutedEventArgs e)
{
    var name = (Image)sender;
    name.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
    name.RenderTransform = new TranslateTransform();
    var translate = (TranslateTransform)name.RenderTransform;

    translate.X += e.Delta.Translation.X;
    translate.Y += e.Delta.Translation.Y;

}

它不适用于运行时映像。我为每个图像控件制作了一个相同的事件,用于拖动它不起作用,错误是什么,需要帮助..

0 个答案:

没有答案