在我的XAML我有一個畫布列表框,並在網格中的一些文本框和一個reactangle:從代碼移到一個矩形在畫布上,在WPF背後
Title="MainWindow" Height="350" Width="500" WindowStartupLocation="CenterScreen">
<Grid>
<ListBox HorizontalAlignment="Left"
Margin="12,12,0,12"
Name="listBoxContainer"
Width="120">
<ListBoxItem Content="Item1" />
<ListBoxItem Content="Item2" />
<ListBoxItem Content="Item3" />
</ListBox>
<TextBox Height="23"
Margin="138,12,85,0"
Name="textBoxAddress"
VerticalAlignment="Top" />
<TextBox Margin="138,41,85,12"
Name="textBoxMsg" />
<Button Content="Button"
Name="buttonAnimation"
Width="75"
Margin="0,10,5,0"
Height="23"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Click="Button1Click" />
<Canvas Name="CanvasAnimation">
<Rectangle Canvas.Left="408"
Canvas.Top="140"
Height="50"
Name="rectAnimation"
Stroke="Black"
Width="50" />
</Canvas>
</Grid>
從後面我的代碼,我可以移動從其位置到距離的矩形:
private void Button1Click(object sender, RoutedEventArgs e)
{
var trs = new TranslateTransform();
var anim3 = new DoubleAnimation(0, -200, TimeSpan.FromSeconds(2));
trs.BeginAnimation(TranslateTransform.XProperty, anim3);
trs.BeginAnimation(TranslateTransform.YProperty, anim3);
CanvasAnimation.RenderTransform = trs;
}
我想知道如何通過座標將矩形從其位置移動到另一個位置?像具有矩形移動到列表框或文本框
是的,你是對的。想你的解決方案,但不是最優的xD – 2013-02-20 13:03:56
增加了一個線,以改善畫布=形式的依賴。 – nvoigt 2013-02-20 17:30:16
這實際上起作用,所以直到我對如何解決這個問題有了另一個想法之後,我將使用您的解決方案。謝謝! – 2013-02-25 08:21:16