User Tools

Site Tools


notes:uwp:roaming

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
notes:uwp:roaming [2017/01/30]
admin
notes:uwp:roaming [2017/01/30] (current)
admin
Line 27: Line 27:
  
  
-Example: Store and read a high priority ​setting. Windows roams the high priority ​setting as quickly as possible ​(applicable only on desktops, not mobile):+Example: Store and read a //​HighPriority// ​setting. Windows roams the //​HighPriority// ​setting as quickly as possible. The //​HighPriority//​ setting is available ​on Windows Desktop but has no effect on Windows Mobile. 
 <code csharp> <code csharp>
 ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;​ ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;​
Line 54: Line 55:
  
 <code csharp> <code csharp>
 +using Windows.Storage;​
 +...
 public sealed partial class MainPage : Page public sealed partial class MainPage : Page
 { {
Line 59: Line 62:
     {     {
         this.InitializeComponent();​         this.InitializeComponent();​
 +    }
  
-        ​Windows.Storage.ApplicationData.Current.DataChanged += +    protected override void OnNavigatedTo(NavigationEventArgs args) 
-            new TypedEventHandler<​ApplicationData,​ object>(OnDataChanged);+    { 
 +        ​Windows.Storage.ApplicationData.Current.DataChanged += OnDataChanged;​ 
 +    } 
 +     
 +    protected override void OnNavigatedFrom(NavigationEventArgs args) 
 +    { 
 +        Windows.Storage.ApplicationData.Current.DataChanged -= OnDataChanged;
     }     }
  
     // OnDataChanged is invoked whenever roaming data changes.     // OnDataChanged is invoked whenever roaming data changes.
     private void OnDataChanged(ApplicationData appData, object args)     private void OnDataChanged(ApplicationData appData, object args)
 +    {
 +        Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,​
 +            () => UpdateFromSettings());​
 +    }
 +
 +    private void UpdateFromSettings()
     {     {
         ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;​         ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;​
Line 83: Line 99:
         }         }
     }     }
- +    ​ 
-    // A custom method to change the roaming settings+    // For testing
-    ​// Call it for example from a Button_Click event handler. +    ​private ​void TestButton_Click(object senderRoutedEventArgs e)
-    public ​void UpdateSettings(string test1int test2)+
     {     {
         ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;​         ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;​
  
-        roamingSettings.Values["​TestStr"​] = test1+        ​// Change the roaming settings. 
-        roamingSettings.Values["​TestInt"​] = test2;+        ​roamingSettings.Values["​TestStr"​] = "​Testing"​
 +        roamingSettings.Values["​TestInt"​] = 88;
  
-        // Signal the change ​in the settings.+        // Signal the change.
         ApplicationData.Current.SignalDataChanged();​         ApplicationData.Current.SignalDataChanged();​
-    } 
- 
- 
-    // For testing. 
-    private void TestButton_Click(object sender, RoutedEventArgs e) 
-    { 
-        UpdateSettings("​Testing",​ 888); 
     }     }
 } }
notes/uwp/roaming.txt · Last modified: 2017/01/30 by admin