2012-02-25 37 views
1

我會直接去解決這個問題。在我的代碼,有省略號的陣列,即
Ellipse[] players = new Ellipse[11];
然後,我用DoubleAnimationWithKeyFrames在畫布動畫這些橢圓,用將動畫分配給WPF中的多個對象

sboard.Children.Add(anim); 
sboard.Children.Add(anim2); 
Storyboard.SetTargetName(anim, players[player - 1].Name); 
Storyboard.SetTargetName(anim2, players[player - 1].Name); 
Storyboard.SetTargetProperty(anim, new PropertyPath(Canvas.LeftProperty)); 
Storyboard.SetTargetProperty(anim2, new PropertyPath(Canvas.TopProperty)); 

但我想移動一些的TextBlocks這些橢圓。我如何將相同的anim和anim2分配給這些TextBlocks?

回答

1

將橢圓和TextBlock放入一個容器(網格,堆疊面板,畫布等)或製作一個UserControl,併爲其製作動畫而不是橢圓。

實施例:

<UserControl 
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" 
x:Class="WpfApplication4.UserControl1" 
x:Name="UserControl"> 

<StackPanel x:Name="LayoutRoot"> 
    <Ellipse Fill="#FFF4F4F5" Height="100" Stroke="Black" Width="100"/> 
    <TextBlock TextWrapping="Wrap" Text="Some Text Here" FontSize="32" HorizontalAlignment="Center"/> 
</StackPanel></UserControl> 
相關問題