Windows phone7: Open a webpage on button click? - c#

I just searched, but didn't find a way to create a web link in my Windows phone7 Application. In Android TextView has android:autoLink='Web' In Windows phone7 textblock I didn't find any relevant property.
Tried adding the NavigateURI property in the Hyperlink and it gives an exception. NavigateUri="http://www.google.com"
Really appreciate If someone Can suggest How to do this. Thanks in Advance...!!!!!

Use just the HyperLinkButton Control.
And add this property to your control:
<HyperlinkButton TargetName="_blank" Content="Go To" Click="HyperlinkButton_Click"/>
Finally add the click event handler to launch the browser using the BrowserTask :
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri("http://www.google.com");
webBrowserTask.Show();
}

Related

Open Links In Another TabPage WebControl

I have a tabControl with two tabPages each with their own Awesomium WebConrol. I need links from one WebControl to open in the other WebControl. I'm currently using VS 2012.
How would that work? Is it even possible to do?
You need to add target="_blank" to your links. This way you will be able to capture webControl.ShowCreatedWebView event. In this event you will have target link e.TargetURL. You can load it to another webControl object, like in initialisation.
Your link:
Link
Your code (webControl1 in first tab, this.webControl2 in second):
this.webControl1.ShowCreatedWebView += this.webControl1_ShowCreatedWebView;
private void webControl1_ShowCreatedWebView(object sender, Awesomium.Core.ShowCreatedWebViewEventArgs e)
{
webControl2.Source = e.TargetURL;
}

Navigation error

I have a hyperlink button in my Silverlight 4 application. I want to download an apk file when I click on this link. I am able to download file but my problem is that when I click on link it downloads the file and trie to navigate on that link so it shows the dialog for file download and raises an exception.
and the code behind hyperlink button is
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
Uri myAbsoluteUri = new Uri(Application.Current.Host.Source,"../download/ItimHRMSAndroidApp.apk");
HtmlPage.Window.Navigate(myAbsoluteUri);
}
I just want to open the download link - not actually navigating to that page.
Set the URI within the markup:
<HyperlinkButton x:Name="MyButton" TargetName="_blank" Content="Download APK" NavigateUri="/download/ItimHRMSAndroidApp.apk" Canvas.Top="40" Canvas.Left="30"></HyperlinkButton>
And remove the Click event handler:
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
Uri myAbsoluteUri = new Uri(Application.Current.Host.Source,"../download/ItimHRMSAndroidApp.apk");
HtmlPage.Window.Navigate(myAbsoluteUri);
}
Why not try using a Generic Web handler
And return the apk file
Like this post
Hope this helps.
the problem was not of the _target field. it is of the path.

adding Hyperlink in win app

I'm looking for a way to use hyperlinks in a winforms environment.
I found that it uses System.Web.UI.WebControls; but when i tried to use it in my program System.Web was as far as it would go.
So I checked the refrences but also no System.Web.UI.WebControls or something like that,
any sugestions?
You can use LinkLabel control. Set text property of LinkLabel to show your web link. You can use "LinkClicked" event to open the web browser as shown below. Hope this helps you.
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(linkLabel1.Text);
}
If your're developing a WinForms application you have to use System.Windows.Forms.LinkLabel control, located in System.Windows.Forms assembly. Controls in System.Web.* are for HTML pages.

			
				
If it's WPF you can do something like this:
<TextBlock>
<Hyperlink NavigateUri="http://www.google.com" RequestNavigate="Hyperlink_RequestNavigate">
Click here
</Hyperlink>
</TextBlock>
And in the code-behind:
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
It will look like this:

C#, Windows Phone 7, Using if-else statement to check which page is displayed

Now I'm developing a Windows Phone 7 app, my app has three buttons located at the applicaton bar. Here is the event handler for these three buttons:
//app bar page navigation
private void ApplicationBarIconButton_Click1(object sender, EventArgs e)
{
if(//check if the current displayed page is mainpage)
{
//do nothing
}
else
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
}
}
private void ApplicationBarIconButton_Click2(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Audios.xaml", UriKind.RelativeOrAbsolute));
}
private void ApplicationBarIconButton_Click3(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Statistics.xaml", UriKind.RelativeOrAbsolute));
}
The button navigation works well except the first one (Button_Click1) because when I first access the main page and click the first button the app will automatically go back to app list.
So I want to use if-else statement to check which page is currently displayed and then decide whether to navigate or stay in the current page.
It looks like you are using the ApplicationBar like you would use a TabBar within iPhone (or similar in Android, Bada, etc too)
In WP7, the Metro style is typpically to use a Pivot or Panorama rather than a "Tab Bar" for this type of navigation.
If you do want to use the ApplicationBar like this:
then you can (the WP7 Marketplace will allow it) but users might feel it's not very Metro.
then you might want to consider disabling the appropriate button rather than just stubbing out the action.
then you can detect the currently shown page using CurrentSource on the NavigationService
Also, please do note that if you try to navigate from MainPage.xaml to the same url MainPage.xaml then you will see an exception - as I recall, the navigation service complains about url fragments not being supported.
Button click1 should be removed from the main page. It makes no sense to have that button there.
Other pages should use the back button to return to the main page. Otherwise you mess up your back stack.

Transition between phone pages

I'm developing a Windows Phone application.
Is there anyway to animate transition between phone pages?
Now, I'm using this to navigate between pages:
NavigationService.Navigate(new Uri("/Views/SelectComponent.xaml", UriKind.Relative));
Thanks.
What you could do is have a "Page1Out" storyboard and "Page2In" storyboard. Then, assign a Completed event handler to the storyboard like this:
Page1Out.Completed += new EventHandler(Page1Out_Completed);
Then handle that event
void Page1Out_Completed(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Views/SelectComponent.xaml", UriKind.Relative));
}
This will play your out transition and then load the new page. In the new page, you want to do something similar, but handle it in the OnNavigatedTo() event.
Hope that helps
The same question with answers can be found here

Categories

Resources