Public Module GridNavigationManager
    Private _forwardStack As New Stack(Of INavigation)()
    Private _backwardStack As New Stack(Of INavigation)()
    Private _isRunning As Boolean = False


    Sub New()

    End Sub

    ''' <summary>
    ''' 是否正在执行导航操作
    ''' </summary>
    ''' <remarks></remarks>
    Public ReadOnly Property IsRunning As Boolean
        Get
            Return _isRunning
        End Get
    End Property


    ''' <summary>
    ''' 是否可以后退
    ''' </summary>
    ''' <returns></returns>
    Public ReadOnly Property CanForward As Boolean
        Get
            Return _forwardStack.Count > 0
        End Get
    End Property

    ''' <summary>
    ''' 是否可以前进
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property CanBackward As Boolean
        Get
            Return _backwardStack.Count > 0
        End Get
    End Property

    ''' <summary>
    ''' 添加导航
    ''' <param name="navigation">导航</param>
    ''' </summary>
    Public Sub Append(navigation As INavigation)
        _backwardStack.Push(navigation)
        _forwardStack.Clear()
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    Public Sub RemoveForward()
        If CanBackward Then _backwardStack.Pop()
    End Sub

    Public Sub Clear()
        _forwardStack.Clear()
        _backwardStack.Clear()
    End Sub

    Public Sub Forward()
        If Not CanForward Then Return
        Dim navigation As INavigation = _forwardStack.Pop()
        _backwardStack.Push(navigation)
        _isRunning = True
        navigation.Forward()
        _isRunning = False
    End Sub

    Public Sub Backward()
        If Not CanBackward Then Return
        Dim navigation As INavigation = _backwardStack.Pop()
        _forwardStack.Push(navigation)
        _isRunning = True
        navigation.Backward()
        _isRunning = False
    End Sub

End Module
