EnterActions 动画未停止且 ExitActions 动画未开始
我公司的一个应用程序通过位于屏幕中心的内容控件显示弹出窗口,该内容控件在需要时隐藏,其后面有一个径向渐变矩形以阻挡 UI 的其余部分,而且看起来不错。我试图在显示矩形和弹出窗口时添加动画,而不仅仅是弹出。进入动画效果很好,但是当我的弹出窗口关闭时,退出动画永远不会被调用,并且进入动画的效果保持不变。
我的 XAML 如下:
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Panel.ZIndex="999" DataContext="{Binding Source={x:Static popup:PopUpService.Instance}}" IsHitTestVisible="{Binding IsPopUpVisible}" Opacity="0">
<Rectangle Fill="{DynamicResource RadialBlackToBlack}" />
<ItemsControl Focusable="False" ItemsSource="{Binding PopUps}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
<DataTrigger Binding="{Binding IsPopUpVisible, Source={x:Static popup:PopUpService.Instance}}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="100" Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="0" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
</Grid>
我做错了什么?
谢谢。
one of my company's applications displays pop ups by means of a content control centered on the screen, which is hidden until needed, and a radial gradient rectangle behind it to block the rest of the UI, plus it looks nice. I am trying to add an animation for when both the rectangle and the pop up are displayed, instead of just popping up. The enter animation works good, but the exit animation is never invoked when my pop up is closed, and the effects of the enter animation remain permanent.
My XAML is as follows:
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Panel.ZIndex="999" DataContext="{Binding Source={x:Static popup:PopUpService.Instance}}" IsHitTestVisible="{Binding IsPopUpVisible}" Opacity="0">
<Rectangle Fill="{DynamicResource RadialBlackToBlack}" />
<ItemsControl Focusable="False" ItemsSource="{Binding PopUps}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
<DataTrigger Binding="{Binding IsPopUpVisible, Source={x:Static popup:PopUpService.Instance}}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="100" Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="0" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
</Grid>
What is it that I'm doing wrong?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不透明度应设置为
1
而不是100
,这会导致问题。 (从100
到1
的动画不可见,从1
到0
的最后一位几乎没有动画时间)也许您还想摆脱冗余:
Duration
放在Storyboards
和所有HoldEnd
上>s,这是默认值。AutoReverse
?The opacity should animate to
1
not100
, this causes the problem. (The animation from100
to1
is not visible, and the last bit from1
to0
gets little animation time)Maybe you also want to get rid of redundancy:
Duration
on theStoryboards
and all theHoldEnd
s, that is the default.AutoReverse
in the first SB?