翻转动画后 Silverlight 屏幕模糊

发布于 2024-11-06 13:16:00 字数 3743 浏览 0 评论 0原文

我创建了一个翻转动画,从项目列表转到编辑对话框。例如,用户看到一个项目列表,双击一个项目进行编辑,然后屏幕翻转以显示包含详细信息的编辑对话框。

除了屏幕上的项目稍微模糊之外,我的实际动画正在工作。当我翻回列表时,它也变得模糊了。

任何人都可以建议这样做的原因。我在下面展示了我是如何实现翻转的。

             <ContentControl x:Name="EditPtrMainContent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <ContentControl.Resources>
                    <Storyboard x:Name="FlipToEditStart">
                        <DoubleAnimation From="0" To="90" Duration="0:0:0.3" Storyboard.TargetName="ContentProjection" Storyboard.TargetProperty="RotationY"/>
                    </Storyboard>
                    <Storyboard x:Name="FlipToEditEnd">
                        <DoubleAnimation From="270" To="360" Duration="0:0:0.3" Storyboard.TargetName="ContentProjection" Storyboard.TargetProperty="RotationY"/>
                    </Storyboard>

                    <Storyboard x:Name="FlipToListStart">
                        <DoubleAnimation From="0" To="-90" Duration="0:0:0.3" Storyboard.TargetName="ContentProjection" Storyboard.TargetProperty="RotationY"/>
                    </Storyboard>
                    <Storyboard x:Name="FlipToListEnd">
                        <DoubleAnimation From="-270" To="-360" Duration="0:0:0.3" Storyboard.TargetName="ContentProjection" Storyboard.TargetProperty="RotationY"/>
                    </Storyboard>
                </ContentControl.Resources>

                <ContentControl.Projection>
                    <PlaneProjection x:Name="ContentProjection"/>
                </ContentControl.Projection>

            </ContentControl>

在代码隐藏中(本质上是一个 MVVM 应用程序,但我很高兴动画控制在视图中,因为它是可视的)

        public EditPtrView()
    {
        InitializeComponent();

        Loaded += OnLoaded;
        Unloaded += OnUnloaded;
        FlipToEditStart.Completed += OnFlipToEditStartCompleted;
        FlipToListStart.Completed += OnFlipToListStartCompleted;
    }

    void OnFlipToListStartCompleted(object sender, EventArgs e)
    {
        EditPtrMainContent.Content = new EditPtrView();
        FlipToListEnd.Begin();
    }

    void OnFlipToEditStartCompleted(object sender, EventArgs e)
    {
        EditPtrMainContent.Content = new NamedTransferView();
        FlipToEditEnd.Begin();
    }

    void OnLoaded(object sender, RoutedEventArgs e)
    {
        // register for MVVM Light messages
        AppMessages.SetFocusMessage.Register(this, OnSetFocus);
        AppMessages.CloseScreenMessage.Register(this, OnCloseScreen);

        AppMessages.ViewLoadedMessage.Send(ViewTypes.BookingsListView);
    }

    void OnUnloaded(object sender, RoutedEventArgs e)
    {
        AppMessages.SetFocusMessage.Unregister(this, OnSetFocus);
        AppMessages.CloseScreenMessage.Unregister(this, OnCloseScreen);
    }

    #region MVVM Light Message Delegates

    private void OnCloseScreen(string screenName)
    {
        switch (screenName)
        {
            case "PtrEdit":
                FlipToListStart.Begin();
                break;
        }
    }

    #endregion

    private void TransfersDataGridDoubleClick(object sender, MouseButtonEventArgs e)
    {
        ShowEditScreen();
    }

    private void EditPtrButtonClick(object sender, RoutedEventArgs e)
    {
        ShowEditScreen();
    }

    private void ShowEditScreen()
    {
        FlipToEditStart.Begin();
    }

如您所见,我通过双击(或单击按钮)和动画来启动动画的前半部分至 90 度。然后,当该动画完成时,我将 ContentControl 的内容更改为新屏幕,并启动第二个动画,从 270 度变为 360 度。通过从编辑屏幕调用 MVVM Light Messenger,我会制作反向动画以返回到列表。所有这些工作正常,但正如我所说,屏幕会稍微模糊。我不是在想象它,​​因为编辑屏幕是一个 View/ViewModel,也在其他地方使用,因此很容易进行比较。 是否需要在动画结束时执行某些操作才能正确重绘屏幕?

I have created a flip animation to go from a list of items to an edit dialogue. For example, the user sees a list of items, double-clicks on an item to edit it and the screen flips to display the edit dialogue with the details.

I have the actual animation working except that items on the screen are slightly blurred. When I flip back to the list that is also blurred.

Can anyone suggest the reason for this. I have shown below how I have achieved the flip.

             <ContentControl x:Name="EditPtrMainContent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <ContentControl.Resources>
                    <Storyboard x:Name="FlipToEditStart">
                        <DoubleAnimation From="0" To="90" Duration="0:0:0.3" Storyboard.TargetName="ContentProjection" Storyboard.TargetProperty="RotationY"/>
                    </Storyboard>
                    <Storyboard x:Name="FlipToEditEnd">
                        <DoubleAnimation From="270" To="360" Duration="0:0:0.3" Storyboard.TargetName="ContentProjection" Storyboard.TargetProperty="RotationY"/>
                    </Storyboard>

                    <Storyboard x:Name="FlipToListStart">
                        <DoubleAnimation From="0" To="-90" Duration="0:0:0.3" Storyboard.TargetName="ContentProjection" Storyboard.TargetProperty="RotationY"/>
                    </Storyboard>
                    <Storyboard x:Name="FlipToListEnd">
                        <DoubleAnimation From="-270" To="-360" Duration="0:0:0.3" Storyboard.TargetName="ContentProjection" Storyboard.TargetProperty="RotationY"/>
                    </Storyboard>
                </ContentControl.Resources>

                <ContentControl.Projection>
                    <PlaneProjection x:Name="ContentProjection"/>
                </ContentControl.Projection>

            </ContentControl>

And in the code-behind (essentially an MVVM app but I am happy with animation control being in the view as it is visual)

        public EditPtrView()
    {
        InitializeComponent();

        Loaded += OnLoaded;
        Unloaded += OnUnloaded;
        FlipToEditStart.Completed += OnFlipToEditStartCompleted;
        FlipToListStart.Completed += OnFlipToListStartCompleted;
    }

    void OnFlipToListStartCompleted(object sender, EventArgs e)
    {
        EditPtrMainContent.Content = new EditPtrView();
        FlipToListEnd.Begin();
    }

    void OnFlipToEditStartCompleted(object sender, EventArgs e)
    {
        EditPtrMainContent.Content = new NamedTransferView();
        FlipToEditEnd.Begin();
    }

    void OnLoaded(object sender, RoutedEventArgs e)
    {
        // register for MVVM Light messages
        AppMessages.SetFocusMessage.Register(this, OnSetFocus);
        AppMessages.CloseScreenMessage.Register(this, OnCloseScreen);

        AppMessages.ViewLoadedMessage.Send(ViewTypes.BookingsListView);
    }

    void OnUnloaded(object sender, RoutedEventArgs e)
    {
        AppMessages.SetFocusMessage.Unregister(this, OnSetFocus);
        AppMessages.CloseScreenMessage.Unregister(this, OnCloseScreen);
    }

    #region MVVM Light Message Delegates

    private void OnCloseScreen(string screenName)
    {
        switch (screenName)
        {
            case "PtrEdit":
                FlipToListStart.Begin();
                break;
        }
    }

    #endregion

    private void TransfersDataGridDoubleClick(object sender, MouseButtonEventArgs e)
    {
        ShowEditScreen();
    }

    private void EditPtrButtonClick(object sender, RoutedEventArgs e)
    {
        ShowEditScreen();
    }

    private void ShowEditScreen()
    {
        FlipToEditStart.Begin();
    }

As you can see I start the first half of the animation on double-click (or button click) and animate to 90 degrees. Then when this animation completes I change the content of the ContentControl to the new screen and start the second animation to go from 270 to 360 degrees. With an MVVM Light Messenger call from the edit screen I do a reverse animation to go back to the list. All of this works OK but, as I said, the screens go slightly blurred. I am not imagining it because the edit screen is a View/ViewModel that is also used elsewhere and so it is easy to compare.
Is there something that needs to be done at the end of the animation to redraw the screen correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

夏末 2024-11-13 13:16:00

添加以下事件处理程序。 -360 或 360 度旋转会导致问题,必须在动画结束后替换为 0。

FlipToEditEnd.Completed += (a, b) => { ContentProjection.RotationY = 0.0; };
FlipToListEnd.Completed += (a, b) => { ContentProjection.RotationY = 0.0; };

Add the following event handlers. -360 or 360 degree rotation causes the problem and must be replaced by 0 after the animation.

FlipToEditEnd.Completed += (a, b) => { ContentProjection.RotationY = 0.0; };
FlipToListEnd.Completed += (a, b) => { ContentProjection.RotationY = 0.0; };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文