Delete forward entry in navigation service?

How to delete all advanced entries in the navigation service?

I tried this, but it crashes.

    while (NavigationService.CanGoForward) NavigationService.RemoveBackEntry();

I know that "RemoveBackEntry ()" seems strange, but there is no RemoveForwardEntry () method.

Any ideas?

Thanks Cohan

Edit 1: I'm a little closer, I can access the direct stack and even output each item there, but I cannot figure out how to delete entries. None of the properties or methods on _frame.ForwardStack or j gives any idea of ​​how to delete these entries.

        Window mainWindow = Application.Current.MainWindow;
        Frame _frame = (Frame)mainWindow.FindName("mainFrame");
        foreach (JournalEntry j in _frame.ForwardStack)
        {
            MessageBox.Show(j.Name);
        }
+5
source share
3 answers
0

, !

:

    void Frame_Navigating(object sender, NavigatingCancelEventArgs e)
    {
        bool b = e.NavigationMode == NavigationMode.Forward;
        if (b)
        {

            e.Cancel = true;
        }
    }

Frame.Navigating, Application, NavigationWindow ( , ).

EDIT:

Behavior a Frame:

public class FrameNavigationBehavior : Behavior<Frame>
{
    public static readonly DependencyProperty CanGoForwardProperty = DependencyProperty.Register(
        "CanGoForward", typeof (bool), typeof (FrameNavigationBehavior), new PropertyMetadata(true));

    public static readonly DependencyProperty CanGoBackwardProperty = DependencyProperty.Register(
        "CanGoBackward", typeof (bool), typeof (FrameNavigationBehavior), new PropertyMetadata(true));

    public static readonly DependencyProperty CanRefreshProperty = DependencyProperty.Register(
        "CanRefresh", typeof (bool), typeof (FrameNavigationBehavior), new PropertyMetadata(true));

    public bool CanGoForward
    {
        get { return (bool) GetValue(CanGoForwardProperty); }
        set { SetValue(CanGoForwardProperty, value); }
    }

    public bool CanGoBackward
    {
        get { return (bool) GetValue(CanGoBackwardProperty); }
        set { SetValue(CanGoBackwardProperty, value); }
    }

    public bool CanRefresh
    {
        get { return (bool) GetValue(CanRefreshProperty); }
        set { SetValue(CanRefreshProperty, value); }
    }

    protected override void OnAttached()
    {
        base.OnAttached();
        AssociatedObject.Navigating += AssociatedObject_Navigating;
    }

    protected override void OnDetaching()
    {
        base.OnDetaching();
        AssociatedObject.Navigating -= AssociatedObject_Navigating;
    }

    private void AssociatedObject_Navigating(object sender, NavigatingCancelEventArgs e)
    {
        NavigationMode navigationMode = e.NavigationMode;
        switch (navigationMode)
        {
            case NavigationMode.New:
                break;
            case NavigationMode.Back:
                if (!CanGoBackward)
                {
                    e.Cancel = true;
                }
                break;
            case NavigationMode.Forward:
                if (!CanGoForward)
                {
                    e.Cancel = true;
                }
                break;
            case NavigationMode.Refresh:
                if (!CanRefresh)
                {
                    e.Cancel = true;
                }
                break;
            default:
                throw new ArgumentOutOfRangeException();
        }
    }
}
+2

If you go to the current page after you go back, you must lose all the data forward as in a web browser or in Windows Explorer.

If you do not want the update to appear in the back list, you can remove the last entry from the back list.

0
source

All Articles