void Back_Clicked(object sender, EventArgs e) { if (MyWebView.CanGoBack) { MyWebView.GoBack(); } }
public override bool OnKeyDown(Android.Views.Keycode keyCode, Android.Views.KeyEvent e) { if (keyCode == Keycode.Back) { if (MyWebView.CanGoBack()) { MyWebView.GoBack(); } return(true); } return(base.OnKeyDown(keyCode, e)); }
public MainPage() { InitializeComponent(); string CurrentUrl = "https://www.baidu.com/"; _webView = new MyWebView() { Source = CurrentUrl, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; BackButton = new Button { Text = "Go Back", BackgroundColor = Color.FromHex("990000"), TextColor = Color.White }; grid = new Grid { //... }; grid.Children.Add(_webView, 0, 6, 0, 7); Content = grid; checkToShowButton(); //Button click BackButton.Clicked += OnBackButtonClicked; void OnBackButtonClicked(object sender, EventArgs e) { _webView.GoBack(); checkToShowButton(); if (_webView.CanGoBack == false) { grid.Children.Remove(BackButton); } } }
private void Nav_BackRequested(object sender, BackRequestedEventArgs e) { // This event handler will occasionally be called twice, so it's important // to check if we've handled it already if (!e.Handled) { if (MyWebView.CanGoBack) { e.Handled = true; MyWebView.GoBack(); } else if (this.Frame.CanGoBack) { e.Handled = true; this.Frame.GoBack(); } } }
private void back()//后退 { MyWebView.GoBack(); }
public MainPage() { InitializeComponent(); string CurrentUrl = "https://www.baidu.com/"; _webView = new MyWebView() { Source = CurrentUrl, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; BackButton = new Button { Text = "Go Back", BackgroundColor = Color.FromHex("990000"), TextColor = Color.White }; grid = new Grid { VerticalOptions = LayoutOptions.FillAndExpand, RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, new RowDefinition { Height = new GridLength(50, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(15, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(15, GridUnitType.Absolute) }, new RowDefinition { Height = new GridLength(36, GridUnitType.Absolute) } }, ColumnDefinitions = { new ColumnDefinition { Width = GridLength.Auto }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(50, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(50, GridUnitType.Absolute) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, new ColumnDefinition { Width = GridLength.Auto } } }; grid.Children.Add(_webView, 0, 6, 0, 7); Content = grid; checkToShowButton(); //Button click BackButton.Clicked += OnBackButtonClicked; void OnBackButtonClicked(object sender, EventArgs e) { _webView.GoBack(); checkToShowButton(); if (_webView.CanGoBack == false) { grid.Children.Remove(BackButton); } } }