0

我到处寻找我能想到的地方,但我找不到这个问题的答案......

我想为 windows phone 7(xaml 和 c#)制作一种模板故事板,然后使用该故事板以相同的方式为多个对象设置动画。(即同时将所有对象旋转 90 度)有什么想法吗?

它必须动态完成。我的意思是我想在程序中将不同的对象分配给几个不同的故事板,所以它不能是静态的。

到目前为止,我面临的主要问题是情节提要必须停止才能再次使用,因此它们不能同时运行。但是我在想,如果我可以制作 Storyboard 的临时副本,我可以同时运行它们吗?请给我您的任何想法。提前致谢!

我在网格中初始化我的对象(矩形),如下所示:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
   <Rectangle Name="rec1" Height="80" Width="10" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,30,140,0">
      <Rectangle.RenderTransform>
         <RotateTransform x:Name="rec1Transform" Angle="0" CenterX="5" CenterY="-10" />
      </Rectangle.RenderTransform>
   </Rectangle>
   <Rectangle Name="rec2" Height="10" Width="80" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,55,0">
   .
   .
   .
   </Rectangle>
</Grid>

此刻,我有 4 个想要多次使用的通用故事板,并且我正在使用一系列按钮来模仿所有的动画。例如:

我的故事板

private void rotate1(object parameter, object secondParameter, String Target)
{

   oneTwo.Stop();
   oneTwo.Children[0].SetValue(Storyboard.TargetNameProperty, Target);
   oneTwo.Begin();
}

private void rotate2(object parameter, object secondParameter, String Target)
{
   twoThree.Stop();
   twoThree.Children[0].SetValue(Storyboard.TargetNameProperty, Target);
   twoThree.Begin();
}

private void rotate1Inverse(object parameter, object secondParameter, string Target)
{
   twoOne.Stop();
   twoOne.Children[0].SetValue(Storyboard.TargetNameProperty, Target);
   twoOne.Begin();
}

private void rotate2Inverse(object parameter, object secondParameter, string Target)
{
   threeTwo.Stop();
   threeTwo.Children[0].SetValue(Storyboard.TargetNameProperty, Target.ToString());
   threeTwo.Begin();
}

我的模拟按钮

//Rotate Buttons
private void button_Click1(object sender, RoutedEventArgs e)
{
    rec1Transform.CenterY = -10;

    rotate2(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec1Transform");
}

private void button_Click2(object sender, RoutedEventArgs e)
{
    rec2Transform.CenterX = -10;

    rotate1(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec2Transform");
}

private void button_Click3(object sender, RoutedEventArgs e)
{
    rec3Transform.CenterY = -10;

    rotate1(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec3Transform");
}

private void button_Click4(object sender, RoutedEventArgs e)
{
    rec4Transform.CenterX = -10;

    rotate2(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec4Transform");
}

private void button_Click5(object sender, RoutedEventArgs e)
{
    rec5Transform.CenterY = -10;

    rotate2(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec5Transform");
}

private void button_Click6(object sender, RoutedEventArgs e)
{
    rec6Transform.CenterX = -10;

    rotate2(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec6Transform");
}

private void button_Click7(object sender, RoutedEventArgs e)
{
    rec7Transform.CenterY = -10;

    rotate1(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec7Transform");
}

//Inverse Rotate Buttons
private void button_Click1_Inverse(object sender, RoutedEventArgs e)
{
    rec1Transform.CenterY = 90;

    rotate1Inverse(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec1Transform");
}

private void button_Click2_Inverse(object sender, RoutedEventArgs e)
{
    rec2Transform.CenterX = 90;

    rotate2Inverse(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec2Transform");
}

private void button_Click3_Inverse(object sender, RoutedEventArgs e)
{
    rec3Transform.CenterY = 90;

    rotate2Inverse(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec3Transform");
}

private void button_Click4_Inverse(object sender, RoutedEventArgs e)
{
    rec4Transform.CenterX = 90;

    rotate1Inverse(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec4Transform");
}

private void button_Click5_Inverse(object sender, RoutedEventArgs e)
{
    rec5Transform.CenterY = 90;

    rotate1Inverse(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec5Transform");
}

private void button_Click6_Inverse(object sender, RoutedEventArgs e)
{
    rec6Transform.CenterX = 90;

    rotate1Inverse(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec6Transform");
}

private void button_Click7_Inverse(object sender, RoutedEventArgs e)
{
    rec7Transform.CenterY = 90;

    rotate2Inverse(RotateTransform.AngleProperty, PlaneProjection.RotationZProperty, "rec7Transform");
}

问题是我想同时在多达 20 个矩形上同时使用这 4 个基本情节提要,从而使所有 20 个矩形一致地设置动画。但我不希望为每个矩形分配一个静态故事板,因为我想应用于每个矩形的故事板每秒左右发生变化。我还将同时使用所有 4 个故事板。(即,我将对 3 个矩形使用“oneTwo”,对 5 个矩形使用“twoThree”,对 8 个矩形使用“twoOne”,对 2 个矩形使用“threeTwo”)

我希望一切都说得通。该程序仅基于同时为许多矩形设置动画,任何帮助或建议将不胜感激。

4

1 回答 1

0

尝试在堆栈面板中绑定矩形

 <Listbox> 
 <ListBox.ItemTemplate>        
  <DataTemplate> 
 <StackPanel>
 <StackPanel.Resources>
    <Storyboard x:Name="FirstStoryBoard">
        <DoubleAnimation Storyboard.TargetName="rectangle"
                         Storyboard.TargetProperty="Width"
                         From="0"
                         To="1"
                         //AutoReverse="True"
                         Duration="00:00:01" />
    </Storyboard>
 </StackPanel.Resources>
 <Rectangle Name="rectangle" Fill={Binding colour}>

 </Rectangle>

 </StackPanel>

 </ListBox.ItemTemplate>
 </DataTemplate> 
 </Listbox>

然后在列表框中使用颜色进行绑定..引用 web 中列表框项目中的绑定。

然后单击按钮启动故事板。故事板子矩形增加了它的宽度

FirstStoryboard.begin();

于 2012-08-09T09:39:42.197 回答