文章出處
文章列表
微軟的wp8.1 sdk相比之前wp8 sdk以及相關dll類庫,微軟又重新編譯過,相關系統類庫也經過精簡,刪改了部分傳統dll庫中的方法對象,很多常用方法對象被寫進Windows.UI為前綴的命名空間中,可以看出微軟wp8.1經過了一定的優化。
此處功能設計描述為,觸摸一次返回鍵,提示是否退出app,再點一次即關閉app。
1 <Grid Background="#F5F5F5" DataContext="{Binding Path=MainPageViewModel, Source={StaticResource Locator}}"> 2 <Grid Canvas.ZIndex="10000" Visibility="{Binding ExitNotificationVisible}" Height="30" Background="Red" VerticalAlignment="Top"> 3 <TextBlock FontSize="14" Text="提示: 再按一次返回鍵退出支付寶" VerticalAlignment="Center" Margin="10 0 0 0" /> 4 </Grid> 5 <ContentControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Content="{Binding DynamicContent}" /> 6 </Grid>
1 using System; 2 using Windows.UI.Xaml; 3 using Windows.UI.Xaml.Controls; 4 using Windows.UI.Popups;
1 public class MainPageViewModel : Core.ViewModelBase 2 { 3 public MainPageViewModel() 4 { 5 InitData(); 6 if(DynamicContent == null) 7 { 8 DynamicContent = ViewControlLocator.Instance.RegisterViewControl<HomePage, HomePageViewModel>(true); 9 } 10 //---物理返回鍵api--- 11 Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed; 12 } 13 14 #region attribute 15 //---計時器--- 16 DispatcherTimer timer = null; 17 int timesToTick = 2; 18 19 private UserControl m_DynamicContent; 20 public UserControl DynamicContent 21 { 22 get { return m_DynamicContent; } 23 set { m_DynamicContent = value; RaisePropertyChanged("DynamicContent"); } 24 } 25 26 private Visibility m_ExitNotificationVisible; 27 public Visibility ExitNotificationVisible 28 { 29 get { return m_ExitNotificationVisible; } 30 set { m_ExitNotificationVisible = value; RaisePropertyChanged("ExitNotificationVisible"); } 31 } 32 #endregion 33 34 #region method 35 private void InitData() 36 { 37 ExitNotificationVisible = Visibility.Collapsed; 38 } 39 40 //---關閉事件--- 41 void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e) 42 { 43 e.Handled = true; 44 if (ExitNotificationVisible == Visibility.Collapsed) 45 { 46 ExitNotificationVisible = Visibility.Visible; 47 48 if(timer == null) 49 { 50 timer = new DispatcherTimer(); 51 } 52 timer.Interval = TimeSpan.FromSeconds(2); 53 timer.Tick += timer_Tick; 54 timer.Start(); 55 } 56 else 57 { 58 App.Current.Exit(); 59 } 60 } 61 62 //---到時沒有執行關閉操作,隱藏關閉操作提示--- 63 void timer_Tick(object sender, object e) 64 { 65 timesToTick--; 66 if (timesToTick == 0) 67 { 68 timesToTick = 2; 69 timer.Tick -= timer_Tick; 70 timer.Stop(); 71 ExitNotificationVisible = Visibility.Collapsed; 72 } 73 } 74 #endregion 75 }
文章列表
全站熱搜