-->

Monday, July 28, 2014

How to add Hyperlink button control by using code in windows phone

How to add Hyperlink button control by using code in windows phone

In previous article we have already learned about  Hyperlink Button control.  Using the HyperlinkButton control you can navigate one page to another in windows phone. The following example creates a HyperlinkButton control named hyper and then adds it to ContentPanel grid.

To add the Hyperlink Button control by using code

Open MainPage.xaml.cs.

Add the following code in the constructor.
C#

public MainPage()
        {
            InitializeComponent();
            HyperlinkButton h1 = new HyperlinkButton();
            h1.Content = "My Button";
            ContentPanel.Children.Add(h1);
            h1.Click += new RoutedEventHandler(HyperlinkButton_Click);


            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();

        }

 private void HyperlinkButton_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/secondpage.xaml", UriKind.Relative));
        }

Create Hyperlink Button control instance , assign string to the content property of Hyperlink Button. Now add this control into Content Panel. When we click on it then page navigate to other page. The name of other page is "secondpage.xaml". So raise click event for that, using NavigationService.Navigate ( ) method you can move one page to another.

Code generate the following code

How to add Hyperlink button control by using code in windows phoneHow to add Hyperlink button control by using code in windows phone


Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved