EnterActions 动画未停止且 ExitActions 动画未开始

发布于 2024-12-08 04:44:30 字数 2227 浏览 0 评论 0原文

我公司的一个应用程序通过位于屏幕中心的内容控件显示弹出窗口,该内容控件在需要时隐藏,其后面有一个径向渐变矩形以阻挡 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白日梦 2024-12-15 04:44:30

不透明度应设置为 1 而不是 100,这会导致问题。 (从 1001 的动画不可见,从 10 的最后一位几乎没有动画时间)

也许您还想摆脱冗余:

  1. 不要两次或不必要地设置属性,将 Duration 放在 Storyboards 和所有 HoldEnd 上>s,这是默认值。
  2. 为什么第一个 SB 中有一个AutoReverse

The opacity should animate to 1 not 100, this causes the problem. (The animation from 100 to 1 is not visible, and the last bit from 1 to 0 gets little animation time)

Maybe you also want to get rid of redundancy:

  1. Do not set properties twice or unnecessarily, drop the Duration on the Storyboards and all the HoldEnds, that is the default.
  2. Why is there an AutoReverse in the first SB?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文