如何解决“ System.Windows.Interactivity.EventTrigger”必须将IsFrozen设置为false才能进行修改
故事板完成后,我正在尝试执行命令。但是这样做,我得到一个InvalidOperationException:'类型'System.Windows.Interactivity.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:内容放置在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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。