我正在尝试在故事板完成后执行一个命令。但这样做会得到InvalidOperationException:"类型为"System.Windows.Interactive.EventTrigger"的指定值必须将IsFrozen设置为false才能修改。">
这是我的代码:
<ItemsControl x:Name="ItemsControl"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Width="250">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border x:Name="MainBorder"
Background="Gray"
Margin="10"
Height="100">
<Border.RenderTransform>
<TranslateTransform X="0"/>
</Border.RenderTransform>
<Button BorderThickness="0"
BorderBrush="Transparent"
Background="Transparent"
Foreground="Black"
Width="20"
Height="20"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Content="x">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Completed">
<i:InvokeCommandAction Command="{Binding DataContext.ClearToastCommand, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
CommandParameter="{Binding .}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<DoubleAnimation By="260"
Duration="0:0:1"
Storyboard.TargetName="MainBorder"
Storyboard.TargetProperty="RenderTransform.X">
<DoubleAnimation.EasingFunction>
<PowerEase EasingMode="EaseOut" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.Items>
<system:String>ItemsControl Item #1</system:String>
</ItemsControl.Items>
</ItemsControl>
谢谢你的帮助!
好的,通过将i:stuff放在Storyboard之外并在EventTrigger中使用SourceName找到了一个有效的解决方案。
<ItemsControl x:Name="ItemsControl"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Width="250">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border x:Name="MainBorder"
Background="Gray"
Margin="10"
Height="100">
<Border.RenderTransform>
<TranslateTransform X="0"/>
</Border.RenderTransform>
<Button BorderThickness="0"
BorderBrush="Transparent"
Background="Transparent"
Foreground="Black"
Width="20"
Height="20"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Content="x">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Completed"
SourceName="sb">
<i:InvokeCommandAction Command="{Binding DataContext.ClearToastCommand, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
CommandParameter="{Binding .}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard x:Name="sb">
<DoubleAnimation By="260"
Duration="0:0:1"
Storyboard.TargetName="MainBorder"
Storyboard.TargetProperty="RenderTransform.X">
<DoubleAnimation.EasingFunction>
<PowerEase EasingMode="EaseOut" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.Items>
<system:String>ItemsControl Item #1</system:String>
</ItemsControl.Items>
</ItemsControl>