Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
466 views
in Technique[技术] by (71.8m points)

c# - want to open Link in external browser of WP7

The architecture is like:
On click of a button an HTML page opens which contains a link in it. On clicking the links I want to open it in external (default) browser of WP7 such that the application closes and link opens externally. How can I implement this?
Added this control in xaml file:

<phone:WebBrowser Name="browser" Margin="0,78,0,0" />

On button click:

   private void Information_Loaded(Object sender,RoutedEventArgs e)
   {
       Assembly assembly = Assembly.GetExecutingAssembly();

       using (Stream stream = assembly.GetManifestResourceStream("index_en.html"))
       {
           using (StreamReader reader = new StreamReader(stream))
           {
               string html = reader.ReadToEnd();

               browser.NavigateToString(html);                   
           }
       }

Now index_en.html has a link which is to be opened in external browser.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Normally, you would do so using Target property on <a> tag. But, in WP7 (at least in Emulator), this does not work.

What you could do is intercept using Navigating event something like following:

void WebBrowser1_Navigating(object sender, NavigatingEventArgs e)
{
    if (IsSupposedToOpenInPhoneBrowser(e.Uri))
    {
        e.Cancel = true;
        WebBrowserTask task = new WebBrowserTask();
        task.URL = e.Uri.ToString();
        task.Show();
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...