Fade In Fade Out Transition между 2 Windows в WPF - PullRequest
0 голосов
/ 03 августа 2020

Ниже представлена ​​моя попытка создать переход между windows в WPF, но я не могу понять, что методу TransitionStoryboard.Begin() нужно в качестве параметра. Я смог исчезнуть / появиться в одном окне, предоставив методу экземпляр одного из переданных в windows, но не понимаю, как передать оба windows. В документации MS говорится о «содержащем объекте» типа FrameworkContentElement или установке TargetName, но ... Я застрял!

Спасибо за любую помощь, которую вы можете предложить.

Imports System.Runtime.CompilerServices
Imports System.Windows.Media.Animation


<Assembly: InternalsVisibleTo("ApplicationStartingTests")>


Friend Module WindowFadeTransition
    Friend Sub Transition(from As Window,
                          [to] As Window)

        ConfigureFromAnimation(from)
        ConfigureToAnimation([to])

        PlayTransition()
    End Sub


    Private Sub ConfigureFromAnimation(from As DependencyObject)
        Const invisible As Double = 0
        Dim fadeOutAnimation As New DoubleAnimation

        With fadeOutAnimation
            .To = invisible
            .Duration = Duration
        End With

        TransitionStoryboard.Children.Add(fadeOutAnimation)
        Storyboard.SetTarget(from,
                             fadeOutAnimation)
        Storyboard.SetTargetProperty(fadeOutAnimation,
                                     New PropertyPath(UIElement.OpacityProperty))
    End Sub


    Private Sub ConfigureToAnimation([to] As DependencyObject)
        Const visible As Double = 1
        Dim fadeInAnimation As New DoubleAnimation

        With fadeInAnimation
            .To = visible
            .Duration = Duration
        End With

        TransitionStoryboard.Children.Add(fadeInAnimation)
        Storyboard.SetTarget([to],
                             fadeInAnimation)
        Storyboard.SetTargetProperty(fadeInAnimation,
                                     New PropertyPath(UIElement.OpacityProperty))
    End Sub


    Private Sub PlayTransition()
        TransitionStoryboard.Begin() '<---- What goes in here?'
    End Sub


    Private ReadOnly Property Duration As New Duration(TimeSpan.FromSeconds(0.7))

    Private ReadOnly Property TransitionStoryboard As New Storyboard
End Module
...