在Windows 8商店App中无法使用DoubleAnimation.SetValue方法

时间:2013-02-05 19:58:01

标签: c# windows storyboard

这是我的XAML代码,

     <Grid>
         <Grid.Resources>
              <Storyboard x:Name="myStoryboard">
                   <DoubleAnimation x:Name="myDoubleAnimation" Storyboard.TargetProperty="Opacity" From="1.0" To="0.0" Duration="0:0:0.2" AutoReverse="True"/>
               </Storyboard>
          </Grid.Resources>

          <Grid x:Name="op_food" PointerEntered="op_PointerEntered">
                <TextBlock Text="Food"/>
          </Grid>

          <Grid x:Name="op_cineplex" PointerEntered="op_PointerEntered">
               <TextBlock Text="Cineplex"/>
          </Grid>
     </Grid>

和C#功能,

    private void op_PointerEntered(object sender, PointerRoutedEventArgs e)
    {
        myStoryboard.Stop();
        Grid myGrid = (Grid)sender;
        myDoubleAnimation.SetValue(Storyboard.TargetProperty,myGrid.Name);
        myStoryboard.Begin();
    }

现在这是我执行此任务时所遵循的链接,而智能感知无法找到故事板 - &gt; http://blogs.msdn.com/b/silverlight_sdk/archive/2008/03/26/target-multiple-objects-properties-with-one-animation-silverlight.aspx

所以我在这段代码中错了?

1 个答案:

答案 0 :(得分:0)

我相信你正在寻找Storyboard.TargetNameProperty,而不是“TargetProperty”(你试图设置其属性为动画的元素的名称,而不是属性名称本身。)

myDoubleAnimation.SetValue(Storyboard.TargetNameProperty, myGrid.Name);