-2

我已经在窗口的资源中定义了故事板。当我在文件后面的代码中访问这个故事板时,发生了以下错误

“在 MainWindow 的名称范围内找不到‘this’名称”

我的代码是

     Storyboard sb = this.Resources["transferToBasketStoryboard"] as Storyboard
    sb.Begin();

谁能帮我??

4

1 回答 1

1

验证您是否在window.resources范围内创建了此 Storyboard,因此 MainWindow.Xaml 应以:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns: ..... 
    x:Class="myWpfApplication.MainWindow"
    Title="MainWindow" Height="350" Width="525">
<Window.Resources>// the resource should be here
    <Storyboard x:Key="transferToBasketStoryboard">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" Storyboard.TargetName="textBlock">
            <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="60"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</Window.Resources>
于 2012-08-18T04:40:16.427 回答