2015-04-08 26 views
0

我在C Sharp中爲簡單的Surface Table應用程序編程。如何在Surface應用程序中移動圖片(智能表,C Sharp .Net 4)

我有一個畫布和圖像幀:

<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.Left','Canvas.Top',等等來移動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); 
} 

我不知道往哪裏放這些代碼,我不能在我的表面代碼中使用這些類。

任何人都可以給我一些建議嗎?謝謝:)

回答

0

您發現的代碼似乎與GDI和System.Drawing有關,Surface應用程序使用WPF。

您可以通過設置Canvas.LeftCanvas.Top附加屬性來移動畫布內的元素。

你會怎麼做:在你的代碼

Canvas.SetLeft(imgKeyboard, 1000)Canvas.SetTop(imgKeyboard, 500) 設置imgKeyboard圖像元素的位置。

您也可以調查使用Storyboard移動圖像,請參閱:

Storyboards on MSDN

+0

謝謝!你的建議非常有幫助。 –

+0

謝謝@ ZhenLi,如果這個答案解決了你的問題,請將其標記爲答案。 – Clint

相關問題