2016-01-21 26 views
2

我有一個Windows Phone 8.1通用應用程序,它接收推送通知。當點擊烤麪包時,會打開應用並將參數發送到特定頁面。我的問題是,它只有當我點擊烤麪包時關閉應用程序纔有效。如果應用程序在我收到通知時打開,然後單擊它,它會將我引導至應用程序,但不會將參數發送到特定頁面(ImageFullScreen)。你知道做什麼需要做到這一點?Toast當單擊並且應用程序已經打開時,不會將參數發送到頁面C#

App.Xaml.Cs:

sealed partial class App : Application 
{ 
    public string NavigateText { get; set; } 

    public App() 
    { 
     this.InitializeComponent(); 
     this.Suspending += OnSuspending; 

    } 

    protected override void OnLaunched(LaunchActivatedEventArgs e) 
    { 
     var launchString = e.Arguments; 
     (App.Current as App).NavigateText = launchString.ToString(); 

     if (System.Diagnostics.Debugger.IsAttached) 
     { 
      this.DebugSettings.EnableFrameRateCounter = true; 
     } 


     Frame rootFrame = Window.Current.Content as Frame; 

     if (rootFrame == null) 
     { 
      // Create a Frame to act as the navigation context and navigate to the first page 
      rootFrame = new Frame(); 
      // Set the default language 
      rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; 

      rootFrame.NavigationFailed += OnNavigationFailed; 

      if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 
      { 
       //TODO: Load state from previously suspended application 
      } 

      // Place the frame in the current Window 
      Window.Current.Content = rootFrame; 
     } 

     if (rootFrame.Content == null) 
     { 
      // When the navigation stack isn't restored navigate to the first page, 
      // configuring the new page by passing required information as a navigation 
      // parameter 
      rootFrame.Navigate(typeof(MainPage), e.Arguments); 
     } 
     // Ensure the current window is active 
     Window.Current.Activate(); 

    } 

MainPage.xaml.cs中:

protected override async void OnNavigatedTo(NavigationEventArgs e) 
    { 
     if ((App.Current as App).NavigateText == "") 
     { 
      await RefreshTodoItems(); 
     } 
     else 
     { 
      items2 = await todoTable 
       .Where(todoItem => todoItem.Text == (App.Current as App).NavigateText) 
       .ToCollectionAsync(); 
      TodoItem myItem = items2[0] as TodoItem; 
      Frame.Navigate(typeof(ImageFullScreen), myItem); 
     }   
    } 

ImageFullScreen.Xaml.Cs:

protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
     var myObject = (TodoItem)e.Parameter; 
     img.Source = new BitmapImage(new Uri(myObject.ImageUri)); 

     (App.Current as App).NavigateText = ""; 
    } 

回答

1

的問題是,在if (rootFrame.Content == null)OnLaunched方法沒有執行,因爲該應用程序已經打開(框架的內容是頁面)。只有窗口被激活,並且MainPage中的OnNavigatedTo方法未被調用。

您可以嘗試啓動在OnLaunched方法總是這樣的導航(不if語句):

rootFrame.Navigate(typeof(MainPage), e.Arguments); 
// Ensure the current window is active 
Window.Current.Activate(); 
+0

這樣做的工作。謝謝你救我:) – Vigs

相關問題