Windows Phone 7 application question
I need to create a website "launcher" application for Windows Phone 7. Basically, it only has to be an icon in the application list, that opens the webbrowser and loads a url given within the application.
I am completely ignorant about microsoft dev... I'm a php/java developer and had so far nearly succeeded in avoiding any contact with microsoft products/languages... :) So please be kind.
I installed the microsoft dev tools and got the sample "Mini-Browser" from here (bottom of the list):
http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx
This does pretty much exactly what I want, except I dont want a text box and a go button. I just want to open the browser with a specific url and that's it, then the user can navigate through the site...
I removed the textbox and button, but I can't find a way to load the url (or in this case to call the button1_Click function) automatically, I'm looking for something like "onLoad" in html, for this xaml tag: (line26)
<phone:WebBrowser 开发者_运维技巧HorizontalAlignment="Stretch" Name="webBrowser1" VerticalAlignment="Stretch" Width="Auto" />
So what I want is that when this tag is loaded, it fires the function from MainPage.xaml.cs...
Can someone help?
In your MainPage.xaml.cs you can add the following line to the constructor:
Loaded += new RoutedEventHandler(MainPage_Loaded);
Then in the handler:
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
MyBrowser.Navigate(new Uri("http://example.com"));
}
You may need to give the browser a name using the x:Name="MyBrowser"
attribute in the XAML and then you can just say MyBrowser.Navigate()
...
Check these posts:
Navigating with the WebBrowser Control on WP7
31 Days of Windows Phone | Day #18: WebBrowser Control
You can also try something like this:
private void btn_Click(object sender, RoutedEventArgs e)
{
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.URL = "http://www.http://stackoverflow.com";
webBrowserTask.Show();
}
Hope this will help you.
精彩评论