我目前有兩個按鈕說左右,我希望他們分別左右移動一個方形對象。如何使用silverlight左右移動物體?
當我按左時,它正在做什麼,將正方形向左移動,如果再次向左按,它會從中心向左移動。
我想要它,所以當我按左鍵時,從現在開始左右移動。
我知道原理是像獲取當前對象的位置和分別添加畫布座標,但我該怎麼做?
<UserControl x:Class="phase_2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<Storyboard x:Name="scroll_me">
<DoubleAnimation x:Name="left_ani" To="0" Duration="0:0:01" Storyboard.TargetName="Rect_Animate" Storyboard.TargetProperty="(Canvas.Left)">
<DoubleAnimation.EasingFunction>
<PowerEase EasingMode="EaseOut"></PowerEase>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
<Storyboard x:Name="scroll_me2">
<DoubleAnimation x:Name="right_ani" To="200" Duration="0:0:01" Storyboard.TargetName="Rect_Animate" Storyboard.TargetProperty="(Canvas.Left)">
<DoubleAnimation.EasingFunction>
<PowerEase EasingMode="EaseOut"></PowerEase>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="35"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Canvas Grid.Column="1" Grid.Row="1" x:Name="canvas1">
<Rectangle x:Name="Rect_Animate" Width="35" Height="35" Fill="Red" Canvas.Left="80" />
</Canvas>
<Button x:Name="left_btn" Width="35" Height="35" Content="L" Grid.Column="0" Grid.Row="1" Click="left_btn_Click"/>
<Button x:Name="right_btn" Width="35" Height="35" Content="R" Grid.Column="2" Grid.Row="1" Click="right_btn_Click"/>
</Grid>
你能告訴我們你的代碼嗎? – ChrisF 2010-05-20 18:59:34