尝试制作动画时网格中的触发器导致异常? (给定的对象必须是 TriggerAction 的实例或派生类型)
这是一些简化的 XAML。在尝试运行该程序时,我收到一个异常,指出:
“向‘System.Windows.TriggerActionCollection’类型的集合添加值引发了异常。”行号“106”和行位置“53”。 ---> System.ArgumentException:给定的对象必须是 TriggerAction 的实例或派生类型。
为什么会发生这种情况?
<Grid x:Name="LoginBoxGrid" Width="400" Height="88" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.Triggers>
<Trigger Property="UIElement.IsVisible" Value="True">
<Trigger.ExitActions>
<Storyboard >
<DoubleAnimation Storyboard.TargetName="UNameBoxTranslate"
Storyboard.TargetProperty="X" From="0" To="-800" Duration="0:0:0.5"/>
<DoubleAnimation Storyboard.TargetName="UNameBoxTranslate"
Storyboard.TargetProperty="Y" From="0" To="-800" Duration="0:0:0.5"/>
</Storyboard>
</Trigger.ExitActions>
</Trigger>
</Grid.Triggers>
<TextBox >
<TextBox.RenderTransform>
<TranslateTransform x:Name="UNameBoxTranslate"/>
</TextBox.RenderTransform>
</TextBox>
</Grid>
Here is some simplified XAML. On trying to run the program, I get an exception stating:
'Add value to collection of type 'System.Windows.TriggerActionCollection' threw an exception.' Line number '106' and line position '53'. ---> System.ArgumentException: The given object must be an instance of TriggerAction or a derived type.
Why is this happening?
<Grid x:Name="LoginBoxGrid" Width="400" Height="88" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.Triggers>
<Trigger Property="UIElement.IsVisible" Value="True">
<Trigger.ExitActions>
<Storyboard >
<DoubleAnimation Storyboard.TargetName="UNameBoxTranslate"
Storyboard.TargetProperty="X" From="0" To="-800" Duration="0:0:0.5"/>
<DoubleAnimation Storyboard.TargetName="UNameBoxTranslate"
Storyboard.TargetProperty="Y" From="0" To="-800" Duration="0:0:0.5"/>
</Storyboard>
</Trigger.ExitActions>
</Trigger>
</Grid.Triggers>
<TextBox >
<TextBox.RenderTransform>
<TranslateTransform x:Name="UNameBoxTranslate"/>
</TextBox.RenderTransform>
</TextBox>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
Storyboard
包装在BeginStoryboard
中,因为Storyboard
不是ExitAction
,但BeginStoryboard
是。编辑:
由于退出操作只能在样式和控件模板中使用,因此必须稍微重新组织此示例。这是一种方法:使用
ContentControl
作为普通模板并填充上面的内容。不幸的是,现在这些名称被隐藏在模板扩展中,但这是一个不同的问题,因为我不确切知道它们的用途。Wrap your
Storyboard
in aBeginStoryboard
becauseStoryboard
is not anExitAction
butBeginStoryboard
is.Edit:
Because exit actions can only be used in styles and control templates, this example would have to be reorganized a little bit. Here is one way to do that: use a
ContentControl
as a vanilla template and fill it will the contents above. Unfortunately now the names are now buried inside a template expansion, but that's a different question since I don't know exactly how they are intended to be used.