如何在 Surface Application 中移动图片 (Smart Table, C Sharp .Net 4)

How to move a picture in Surface Application (Smart Table, C Sharp .Net 4)

我正在用 C Sharp 为一个简单的 Surface Table 应用程序编程。

我有一个canvas和一个图像框架:

<Canvas Name="InputCanvas"
        Background="SeaGreen"
        TouchDown="InputCanvas_TouchDown"
        TouchMove="InputCanvas_TouchMove"
        TouchUp="InputCanvas_TouchUp"
        MouseLeftButtonDown="InputCanvas_MouseLeftButtonDown"
        MouseMove="InputCanvas_MouseMove"
        MouseLeftButtonUp="InputCanvas_MouseLeftButtonUp">

        <Image Canvas.Left="0" Canvas.Top="0" 
               Height="610" Width="1590"
               Name="imgKeyboard" Stretch="None" />
</Canvas>

当我像这样将图片放入“imgKeyboard”时:

        BitmapImage kbdBitmap = new BitmapImage();
        kbdBitmap.BeginInit();
        kbdBitmap.UriSource = new Uri(BaseUriHelper.GetBaseUri(this), "Resources/keyboard_1x.png");
        kbdBitmap.EndInit();

        imgKeyboard.Source = kbdBitmap;

键盘图片会出现在图片的中央(图片比canvas小很多)。

当然,我可以通过更改 'Canvas.Left'、'Canvas.Top'、.etc.

来移动 XML 中的键盘图片

但是我想动态移动C Sharp代码中的键盘图片。

我在 MSDN 上找到了一些代码,但它们似乎无关紧要:

private void DrawImagePoint(PaintEventArgs e)
{         
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");

    // Create Point for upper-left corner of image.
    Point ulCorner = new Point(100, 100);

    // Draw image to screen.
    e.Graphics.DrawImage(newImage, ulCorner);
}

我不知道把这些代码放在哪里,我不能在我的 Surface 代码中使用这些 类。

谁能给我一些建议?谢谢:)

您找到的代码似乎与 GDI 和 System.Drawing、Surface 应用程序使用 WPF 有关。

您可以通过设置 Canvas.LeftCanvas.Top 附加属性在 canvas 中移动元素。

你会做:

Canvas.SetLeft(imgKeyboard, 1000) 要么 Canvas.SetTop(imgKeyboard, 500) 在您的代码中设置 imgKeyboard 图像元素的位置。

您还可以研究使用 Storyboard 移动图像,请参阅:

Storyboards on MSDN