3

The exception shown above is thrown on this XAML for a Silverlight 4 application:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="NewtonsCradle.MainPage"
    Width="640" Height="480">
    <StackPanel Orientation="Horiontal">
        <TextBlock Height="100" Name="TestText">Test</TextBlock>
        <StackPanel.Triggers>
            <EventTrigger RoutedEvent="Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation Storyboard.TargetName="TestText" 
                                         Storyboard.TargetProperty="Height" 
                                         To="500"
                                         Duration="0:0:1"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </StackPanel.Triggers>
    </StackPanel>

</UserControl>

The code behind:

    using System.Windows.Controls;

namespace NewtonsCradle
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            // Required to initialize variables
            InitializeComponent();

        }
    }
}

What's up? It seems perfectly reasonable code to me, coming from a WPF background.

4

1 回答 1

4

我想没有人回答过这个问题,但要修复错误使用

您需要将事件触发器实际放在您正在制作动画的控件中,并指定事件的完整路径而不是“加载”使用 Border.Load

 <Border.Triggers>
                    <EventTrigger RoutedEvent="Border.Loaded">
                        <EventTrigger.Actions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetProperty="Height"  From="0" To="Auto" Duration="0:0:1" Storyboard.TargetName="Border1"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger.Actions>
                    </EventTrigger>
</Border.Triggers>
于 2011-01-27T15:51:08.410 回答