2

我需要导航到我的 Metro 应用程序中的 Internet 页面。我的网址是(示例)'http://www.foo.com/#/foo'。问题是 LaunchUriAsync 将 url 剪切为“http://www.foo.com”。

try
{
    Uri uri = new Uri(item.UriCode); 
    await Launcher.LaunchUriAsync(uri);
}
catch (Exception exception)
{
    //TODO
}

我哪里错了?问候。

更新 :

我准确地说 uri = http://www.foo.com/#/foo。所以问题来自 LaunchUriAsync 。

4

2 回答 2

0

我尝试使用相同的代码对您提到的 uri 进行硬编码请检查以下代码:

    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.  The Parameter
    /// property is typically used to configure the page.</param>
    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        try
        {
            Uri uri = new Uri("http://www.foo.com/#/foo");
            await Launcher.LaunchUriAsync(uri);
        }
        catch (Exception exception)
        {
            //TODO
        }
    }

输出如下所示

具有相应 URL 的启动器测试

我认为还有其他问题。可能是item.UriCode随行请查收。

于 2012-12-20T10:57:58.683 回答
0

I think it is difficult to diagnose what is actually wrong from your example.

It appears you are trying to navigate to an anchor within a web page, but doing it with incorrect syntax / pointing to a non-existent anchor. However, your example linked page doesn't seem to contain a navigable anchor.

Assuming that this is actually what you are trying to achieve, try the following example, and you will see that navigation works as expected

Launcher.LaunchUriAsync(new Uri("http://www.hypergurl.com/anchors.html#bottom"));

If this isn't what you are trying to achieve, I would suggest that the presence of the # character in the URI is being interpretted as an anchor reference by IE and that's why you aren't getting the result you require.

于 2012-12-20T11:07:25.157 回答