2012-03-02 223 views
0

首次執行Windows Phone 7應用程序時需要做些事情。我該如何檢查,首先執行?應用程序的第一次執行

+0

首次啓動後安裝?不,你不需要做任何事情,如果這對於應用程序邏輯沒有必要的話 – Ku6opr 2012-03-02 15:20:39

+1

這個評論甚至意味着什麼? – MoonKnight 2012-03-02 15:24:14

+0

對不起,我讀了第一句話作爲一個問題...對不起一次 – Ku6opr 2012-03-02 15:31:14

回答

1

您可以使用IsolatedStorage這一點。詳細信息請參見MSDN。有關基本實現,請參閱this link

在首次啓動和之前,你甚至建立了持續的默認設置,你可以指望的保存的設置數量:

if (IsolatedStorageSettings.ApplicationSettings.Count == 0) 
    MessageBox.Show("No setting avalible - applications fisrt launch!"); 

我把這個在的MainPage的構造。

這應該是你所需要的。希望這可以幫助。

0

或在更短的線 可以在

私人無效Application_Launching做驗證(對象發件人,LaunchingEventArgs E) { }

保存一個變量在所述分離的儲存空間。 嘗試獲取它,如果你不能這意味着它是第一次使用應用程序,但如果你能夠加載變量,那麼應用程序已經開始。

希望它能幫助

1

我也建議你使用IsolatedStorage,而是專門增加一個布爾鑰匙獨立存儲,並驗證它是否設置爲true。

例子:

using System; 
using System.IO.IsolatedStorage; 

/// <summary> 
/// Application Settings 
/// </summary> 
public class AppSettings 
{ 
    /// <summary> 
    /// IsFirstStart IsolatedStorage Key. 
    /// </summary> 
    public const string IsFirstStartKey = "firststart"; 

    /// <summary> 
    /// Gets or sets a value indicating whether this instance is the first start. 
    /// </summary> 
    /// <value> 
    ///  <c>true</c> if this instance is the first start; otherwise, <c>false</c>. 
    /// </value> 
    public static bool IsFirstStart 
    { 
     get 
     { 
      if (IsolatedStorageSettings.ApplicationSettings.Contains(AppSettings.IsFirstStartKey)) 
       return (bool)IsolatedStorageSettings.ApplicationSettings[AppSettings.IsFirstStartKey]; 
      else 
       return true; 
     } 
     set 
     { 
      if (IsolatedStorageSettings.ApplicationSettings.Contains(AppSettings.IsFirstStartKey)) 
       IsolatedStorageSettings.ApplicationSettings[AppSettings.IsFirstStartKey] = value; 
      else 
       IsolatedStorageSettings.ApplicationSettings.Add(AppSettings.IsFirstStartKey, value); 

      IsolatedStorageSettings.ApplicationSettings.Save(); 
     } 
    } 
} 

用法:

if (AppSettings.IsFirstStart == false) 
{ 
    // First Start, do some logic 
    // ... 

    // But remember to set it to true, once it's done! 
    AppSettings.IsFirstStart = true; 
} 
相關問題