这是我的XAML:
<TabControl Name="me" SelectionChanged="me_SelectionChanged">
<TabControl.Resources>
<Storyboard x:Name="fadein" x:Key="fatal">
<DoubleAnimation x:Name="fade" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:3">
</DoubleAnimation>
</Storyboard>
</TabControl.Resources>
<TabItem Header="MyTabItem">
<Grid Background="Black" HorizontalAlignment="Stretch" Opacity="0.7"></Grid>
</TabItem>
</TabControl>
我试图通过C#代码访问fatal
动画,但我无法...
public void me_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender == null)
return;
fatal.Stop();// cant recognize `fatal`
}
C#无法识别fatal
是什么。
我做错了什么?
答案 0 :(得分:2)
您可以执行以下操作:
StoryBoard sb = (StoryBoard)me.FindResource("fatal");
或
StoryBoard sb = (StoryBoard)me.Resources["fatal"];