如何在 Win10 UWP App 中跨多個裝置共享資料

為了使應用程式更具凝聚力,我們經常需要在使用一個 Microsoft 帳戶登入的多個裝置上保持使用者的個人設定和首選項一致。在此示例中,我們使用漫遊資料來儲存和載入 UI 設定,遊戲過程和使用者​​資訊。但漫遊資料有其自身的限制:我們無法在漫遊資料夾中儲存大檔案。系統會暫停程式包中所有應用程式的資料複製到雲端,直到當前大小不再超過最大大小。因此,在此示例中,我們尚未將使用者影象儲存在漫遊資料夾中。相反,它儲存在本地資料夾中。

private async void LoadRoamingData() 
{ 
    //Get background color 
    object color = roamingSettings.Values["BackgroundColor"]; 
    if (color != null) 
    { 
        if (ViewModel.ColorList.Keys.Contains(color.ToString())) 
        { 
            Color backgroundColor = ViewModel.ColorList[color.ToString()]; 
            ViewModel.BackgroundColor = new SolidColorBrush(backgroundColor); 
            comboBackgroundColor.SelectedValue = color.ToString(); 
        } 
    } 
    //Get game process stored in the roaming file 
    try 
    { 
        StorageFile processFile = await roamingFolder.GetFileAsync(processFileName); 
        string process = await FileIO.ReadTextAsync(processFile); 
        int gameProcess; 
        if (process != null && int.TryParse(process.ToString(), out gameProcess) && gameProcess > 0) 
        { 
            ViewModel.GameProcess = gameProcess; 
        } 
    } 
    catch { } 

    //Get user name 
    object userName = roamingSettings.Values["UserName"]; 
    if (userName != null && !string.IsNullOrWhiteSpace(userName.ToString())) 
    { 
        ViewModel.UserName = userName.ToString(); 
    } 
} 

有關更多資訊,請參閱 https://code.msdn.microsoft.com/How-to-share-data-across-d492cc0b