0
我對我的最後一年和IM做關於WPF項目中的學生,但我完全新的WPF,我被分配一些任務,但即時通訊目前停留在如何改變programitically從左right.below畫布上的圖像位置在代碼
<<Window x:Class="changing_bird_position.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="450" Width="800">
<StackPanel>
<Canvas Name="canvas" Background="LightBlue" Width="500" Height="280" Margin="264,0,28,0">
<Image Source="inlandbird.png" Name="Image" Height="43" Canvas.Left="55" Canvas.Top="22"/>
</Canvas>
<Button Content="Button" Click="Button_Click" Width="50" Height="50" Margin="246,0"/>
</StackPanel>
Xaml.cs
public partial class MainWindow : Window
{
Image img = new Image();
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Canvas.SetLeft(img, 200.0);
Canvas.SetTop(img, 200.0);
你可以使用Canvas.GetLeft來獲取圖像的當前位置和使用,在Canvas.SetLeft與增量移動圖像在一個循環內。 Canvas.SetLeft(birdImage,Canvas.GetLeft(birdImage)+ 5); – JTK