locked
button event handler in c# RRS feed

  • Question

  • I WANT TO create a button event handler when a button clik then open a web page in c#

    plz  help

    Wednesday, January 15, 2014 6:29 AM

Answers

  • That would look like this:

    private async void Facebook_Clicked(object sender, RoutedEventArgs e)
    {
        await Launcher.LaunchUriAsync(new Uri("https://www.facebook.com"));
    }

    Wednesday, January 15, 2014 6:42 AM
  • Hi,

    You can create a click event and use Launcher.LaunchUriAsync()

      <Grid>
            <Button x:Name="NavigateButton" Click="NavigateButton_Click" Height="30" Width="100" Content="Navigate"/>
      </Grid>

    private async void NavigateButton_Click(object sender, RoutedEventArgs e)
            {
                Launcher.LaunchUriAsync(new Uri("http://www.google.com"));
            }

    If you want to display the WebPage Inside your App. Then use a WebView.

    <StackPanel>
            <Button x:Name="NavigateButton" Click="NavigateButton_Click" Height="30" Width="100" Content="Navigate"/>
            <WebView x:Name="MyWebView"/>
        </StackPanel>

    private async void NavigateButton_Click(object sender, RoutedEventArgs e)
            {
                MyWebView.Navigate(new Uri("http://www.google.com"));
            }


    srithar


    Wednesday, January 15, 2014 6:43 AM

All replies

  • That would look like this:

    private async void Facebook_Clicked(object sender, RoutedEventArgs e)
    {
        await Launcher.LaunchUriAsync(new Uri("https://www.facebook.com"));
    }

    Wednesday, January 15, 2014 6:42 AM
  • Hi,

    You can create a click event and use Launcher.LaunchUriAsync()

      <Grid>
            <Button x:Name="NavigateButton" Click="NavigateButton_Click" Height="30" Width="100" Content="Navigate"/>
      </Grid>

    private async void NavigateButton_Click(object sender, RoutedEventArgs e)
            {
                Launcher.LaunchUriAsync(new Uri("http://www.google.com"));
            }

    If you want to display the WebPage Inside your App. Then use a WebView.

    <StackPanel>
            <Button x:Name="NavigateButton" Click="NavigateButton_Click" Height="30" Width="100" Content="Navigate"/>
            <WebView x:Name="MyWebView"/>
        </StackPanel>

    private async void NavigateButton_Click(object sender, RoutedEventArgs e)
            {
                MyWebView.Navigate(new Uri("http://www.google.com"));
            }


    srithar


    Wednesday, January 15, 2014 6:43 AM