删除导航服务上的转发条目?

发布于 2024-08-14 07:38:16 字数 651 浏览 1 评论 0原文

如何删除导航服务中的所有转发条目?

我尝试过这个,但它崩溃了。

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

我知道“RemoveBackEntry()”看起来很奇怪,但没有RemoveForwardEntry() 方法。

有什么想法吗?

谢谢, Kohan

编辑 1: 我更近了一点,我可以访问前向堆栈,甚至可以输出其中的每个项目,但我似乎无法弄清楚如何删除这些条目。 _frame.ForwardStack 或 j 上的任何属性或方法都没有提供有关如何删除这些条目的任何见解。

        Window mainWindow = Application.Current.MainWindow;
        Frame _frame = (Frame)mainWindow.FindName("mainFrame");
        foreach (JournalEntry j in _frame.ForwardStack)
        {
            MessageBox.Show(j.Name);
        }

How would one remove all the forward entries in a navigation service?

I tried this but it is crashing.

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

I know "RemoveBackEntry()" seems odd but there is no RemoveForwardEntry() method.

Any ideas?

Thanks,
Kohan

Edit 1:
Im a little closer, i can access the forward stack, and even output each item in there but i can not seem to work out how to remove the entries. None of the properties or methods on _frame.ForwardStack or j give any insight into how to remove these entries.

        Window mainWindow = Application.Current.MainWindow;
        Frame _frame = (Frame)mainWindow.FindName("mainFrame");
        foreach (JournalEntry j in _frame.ForwardStack)
        {
            MessageBox.Show(j.Name);
        }

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

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

发布评论

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

评论(3

七月上 2024-08-21 07:38:16

好吧,答案永远不会太晚!

以下代码将简单地禁用向前导航:

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

            e.Cancel = true;
        }
    }

目前它用于 Frame.Navigating 事件,但它应该适用于 Application 以及 NavigationWindow (但未测试) 。

编辑:

这是框架行为

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();
        }
    }
}

Well, it's never too late for an answer !

The following piece of code will simply disable forward navigation:

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

            e.Cancel = true;
        }
    }

Currently it is for the Frame.Navigating event but it should apply for Application as well as NavigationWindow (did not test though).

EDIT:

Here is a Behavior for 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();
        }
    }
}
我最亲爱的 2024-08-21 07:38:16

我对 wpf 导航进行了更多阅读,如果您可以访问应用程序的 NavigationWindow 实例,则有一个名为 ForwardStack 的属性,它保存向前导航页面的列表。您应该能够从那里添加或删除页面。

我自己还没有尝试过这个,因为我现在没有可以测试这个的项目,所以请告诉我这是否有效,因为我想将来自己尝试一下。

有关完整成员列表,请参阅 msdn 链接: http://msdn.microsoft.com/en-我们/library/system.windows.navigation.navigationwindow_members.aspx

I read into the wpf navigation a little more and if you can get to the instance of NavigationWindow for your application there is a property called ForwardStack that holds the list of forward navigation pages. You should be able to add or remove pages from there.

I have not tried this myself as I do not have a project to test this on right now so let me know if this works as I would like to try this myself in the future.

See msdn link for full member listing: http://msdn.microsoft.com/en-us/library/system.windows.navigation.navigationwindow_members.aspx

度的依靠╰つ 2024-08-21 07:38:16

如果您在后退后重新导航到当前页面,您应该会丢失所有前进数据,就像在 Web 浏览器或 Windows 资源管理器中一样。

如果您不希望刷新显示在返回列表中,您可以从返回列表中删除最后一个条目。

If you renavigate to the current page after you go backwards you should lose all of the forward data just like you would in a web browser or in windows explorer.

If you don't want the refresh to show in the back list you can then remove the last entry from the back list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文