Hyperlink button website - windows-phone-7

I need to put button that after click moves user to website. Can someone tell me what should I put into vb and in xaml?

<HyperlinkButton Content="Click here to learn about Silverlight" NavigateUri="http://www.silverlight.net" TargetName="_blank" />

You can do it also in C#
private void HyperlinkButton_Click(object sender, System.Windows.RoutedEventArgs e)
{
var task = new Microsoft.Phone.Tasks.WebBrowserTask
{
URL = "http://siteaddress.com",
};
task.Show();
}

Related

Navigate to another page on button click

I am developed the Windows mobile application I've added the button for VS blend 2015 , but there's no button navigate to option how to bind to my button for the page sub.xaml
<Button x:Name="button" Content="Enter" Height="42" Margin="122,-113,0,0"
VerticalAlignment="Top" Width="144" Foreground="#FF50CBC5"
Background="#FF0F0E0E" HorizontalAlignment="Left"/>
The hyperlink button gives you the option to navigate to another page onclick.
This screen shot is from Blend.
So change your mark up as follows, including the generated Click handler.
<HyperlinkButton x:Name="button" Click="HyperlinkButton_Click"
Content="Enter" Height="42" Margin="122,-113,0,0"
VerticalAlignment="Top" Width="144" Foreground="#FF50CBC5"
Background="#FF0F0E0E" HorizontalAlignment="Left"/>
Then in your cs, you need to direct the navigation.
// Button to navigate to sub.xaml page.
private void HyperlinkButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// Navigate back to sub.xaml page.
this.Frame.Navigate(typeof(SubPage));
}
You will have a Click event for button. In that click event, write the code as
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/sub.xaml", UriKind.RelativeOrAbsolute));
}
You can do this using following steps.
1st Step - add a new button on your window and change the properties as you wish.
2nd Step - double click on that button. then you will go to the cs file like this.
private void Button_Click(object sender, RoutedEventArgs e)
{
}
3rd Step - create new object of window that you want to navigate and open that, then close current window
private void Button_Click(object sender, RoutedEventArgs e)
{
NewWindow newWindow = new NewWindow();
newWindow.Show();
this.Close();
}
Thanks.

How to go to an xaml page by clicking on the button in WebBrowser control in Windows Phone 7 or 8

I have a XAML Page with a WebBrowser tag. WebBrowser has few text boxes and a button, here my question is after clicking on that button i have to go to a XAML page. How can i do this?
By clicking the button in WebBrowser, i want to go to a XAML Page which is in solution file.
Please help me on this.
I believe you can solve this by listening to the WebBrowser.Navigating event. First do:
myWebBrowser.Navigating += myWebBrowser_Navigating;
Then in the handler method check if the uri navigated to is the pointed to by that button:
private void myWebBrowser_Navigating(object sender, NavigatingEventArgs e)
{
if(e.Uri.AbsolutePath == URI_OF_BUTTON) {
NavigationService.Navigate(new Uri("/otherPage.xaml", UriKind.Relative));
}
}
It sound like Page Navigation.
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Pasta.xaml", UriKind.Relative));
}

Why am I getting a Null reference exception for a Slider value changed event that happens each time the page loads

I am new to creating Windows Phone 7 Apps, I have added a slider to my page to which i have customized the look but when i load the page in the emulator before the page even loads I get a "NullReferenceException" I thought this was because I had not initialized the slider so i changed the settings method to
public settings()
{
InitializeComponent();
sldPassLegnth.Value = (double)3;
}
The value changed event simply looks like this:
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
double d;
d = sldPassLegnth.Value;
}
The xaml for the slider is:
<Slider Style="{StaticResource SliderStyle1}" Margin="24,75,22,352" Name="sldPassLegnth" ValueChanged="Slider_ValueChanged" Background="Black" Foreground="#FF3399FF" Maximum="15" Minimum="3" />
Any insight into this would be great! Thanks in advance.
Try this instead:
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
double d;
d = e.NewValue;
}

using TabControl in windows phone

I read the article about using a TabControl on Windows Phone application. I can avoid it to fire when it is first load. However, the selectionChanged fired twice when user click the tab. Would someone can help me how to fix it. Thanks in advance.
There is my TabControl:
<cc:TabControl Grid.Row="1" SelectionChanged="tabList_SelectionChanged" x:Name="tabList">
<cc:TabItem Height="80" Header="Events" Foreground="Black"/>
<cc:TabItem Height="80" Header="Details" Foreground="Black"/>
<cc:TabItem Height="80" Header="Notes" Foreground="Black" />
</cc:TabControl>
There is cobe behind:
public partial class Tab : PhoneApplicationPage
{
private bool blnFristLoad=true;
public Tab()
{
InitializeComponent();
tabList.SelectionChanged += new SelectionChangedEventHandler(tabList_SelectionChanged);
}
private void tabList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (blnFristLoad == false)
{
TabItem t = (sender as TabControl).SelectedItem as TabItem;
t.Content = "202020";
}
else blnFristLoad = false;
}
It's very obvious in your code. You are adding SelectionChanged event handler twice. One from your XAML code and the other from the code behind. As you are using += symbol, the eventhandler is added as a seperate instance.
Remove one of those statements.
Please use the Pivot control instead of a TabControl for the WindowsPhone. the Pivot control follows the design guidelines for the phone and looks and feels much better.

OnClick on generated Textblock

Howdy,
I'm generating a bunch of Textblocks in a StackPanel. I would love to open another page when clicking on one Textbox:
sp.Children.Add(new TextBlock { Text = "Click me, I wanna open new content" });
How could I do that, it's probably something with "triggers" but I couldn't find anything on the web :-/.
Thanks!
You could use the Toolkit to add a gesture listener for the Tap event.
Alternatively you could use a HyperlinkButton as this contains a Click event.
Edit:
Example of using HyperlinkButton:
var sp = new StackPanel();
var hlb = new HyperlinkButton {Content = "click me"};
hlb.Click += hlb_Click;
sp.Children.Add(hlb);
ContentPanel.Children.Add(sp);
private void hlb_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/AnotherPage.xaml", UriKind.Relative));
}
Use TextBlock.ManipulationStarted event to detect a touch on it.

Resources