博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
让OSChina的Windows Phone客户端支持后退键
阅读量:6996 次
发布时间:2019-06-27

本文共 1731 字,大约阅读时间需要 5 分钟。

hot3.png

接上篇《》,在做的时候就返现自己习惯性的使用后退键,评论的也说互动性不好,所以今天就弄了下让它支持后退键。

public partial class MainPage : PhoneApplicationPage    {        ///         /// 改为一个int计数器或许更好        ///         private Stack
broswerHistory; // Constructor public MainPage() { InitializeComponent(); webBrowser1.Navigated += new EventHandler
(webBrowser1_Navigated); broswerHistory = new Stack
(); } void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) { broswerHistory.Push(webBrowser1.Source); } protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { webBrowser1.Navigate(new Uri("http://m.oschina.net/", UriKind.Absolute)); base.OnNavigatedTo(e); } protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { if (broswerHistory.Count > 1) { try { webBrowser1.InvokeScript("eval", "history.go(-1)"); broswerHistory.Pop(); } catch (Exception ex) { } finally { e.Cancel = true; } } else { MessageBoxResult result = MessageBox.Show(OSChinaResources.Tips_ExitApp, OSChinaResources.Tips_Title, MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) { e.Cancel = true; } } } }

嘿嘿。

转载于:https://my.oschina.net/wingyiu/blog/56249

你可能感兴趣的文章