对于Silverlight 4应用程序,此XAML上引发了上述异常:
<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>
背后的代码:
using System.Windows.Controls;
namespace NewtonsCradle
{
public partial class MainPage : UserControl
{
public MainPage()
{
// Required to initialize variables
InitializeComponent();
}
}
}
怎么了?对我来说,这似乎是完全合理的代码,来自WPF背景。
答案 0 :(得分:4)
我想没有人回答这个问题,但要修复错误使用
您需要将事件触发器实际放在您正在设置动画的控件中,并指定事件的完整路径,而不是&#34; Loaded&#34;使用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>