停止在Web浏览器控件内导航[WPF]

时间:2016-03-29 23:42:53

标签: wpf webbrowser-control

你好,在WinForms中有类似于AllowNavigation的东西吗?

我的搜索没有产生任何令人满意的结果。 基本上我试图在新的wpf窗口中打开一个网页,阻止用户点击该网页上的随机链接并进一步导航。

看到的东西
void browser1_Navigating(object sender, NavigatingCancelEventArgs e)
    {
        e.Cancel = true;
    }

其余代码是:

public Popup_webpage(string ime)
    {
        InitializeComponent();

        browser1.LoadCompleted += browser1_LoadCompleted;
        browser1.Navigating += browser1_Navigating;


        string uri = "www.google.com"
        browser1.Navigate(new Uri(uri, UriKind.Absolute));
    }

    void browser1_LoadCompleted(object sender, NavigationEventArgs e)
    {
        browser1.Visibility = Visibility.Visible;
    }

但它只是让我的网页无法显示?

由于

1 个答案:

答案 0 :(得分:0)

试试这个:

加载页面后,您将分配browser_Navigating事件处理程序。

public Popup_webpage(string ime)
{
    InitializeComponent();

    browser1.LoadCompleted += browser1_LoadCompleted;
    string uri = "www.google.com"
    browser1.Navigate(new Uri(uri, UriKind.Absolute));

    browser1.Navigating += browser1_Navigating;
}

void browser1_LoadCompleted(object sender, NavigationEventArgs e)
{
    browser1.Visibility = Visibility.Visible;
}

void browser1_Navigating(object sender, NavigatingCancelEventArgs e)
{
    e.Cancel = true;
}