Esempio n. 1
0
 public SettingsPage()
 {
     InitializeComponent();
     _settings = (SettingsViewModel) DataContext;
     MapSourceListPicker.SetBinding(ListPicker.SelectedItemProperty, _mapSourceBinding);
     DistanceUnitListPicker.SetBinding(ListPicker.SelectedItemProperty, _distanceUnitBinding);
 }
Esempio n. 2
0
 public DropBoxView()
 {
     InitializeComponent();
     _settings = (SettingsViewModel)DataContext;
     _navHistory.CollectionChanged += (s, e) =>
     {
         switch (e.Action)
         {
             case NotifyCollectionChangedAction.Add:
                 if (_navHistory.Count > 1) _navHistory[_navHistory.Count - 2].Visibility = Visibility.Collapsed;
                 ((FrameworkElement)e.NewItems[0]).Visibility = Visibility.Visible;
                 break;
             case NotifyCollectionChangedAction.Remove:
                 ((FrameworkElement)e.OldItems[0]).Visibility = Visibility.Collapsed;
                 _navHistory[_navHistory.Count - 1].Visibility = Visibility.Visible;
                 break;
         }
     };
     _navHistory.Add(HomePanel);
 }
Esempio n. 3
0
        public void Wake(Action<Version> oldVersionAction = null)
        {
            var setting = LocalServices.LoadLocalSetting("Version");
            var version = setting as string;
            if (version != null) LastRunVersion = new Version(version);

            // Do not load from save if the save version is too old.
            if (LocalServices.HasLocalData && (LastRunVersion == null || LastRunVersion < Globals.BackwardCompatibleVersion))
            {
                // Clear settings.
                LocalServices.ClearLocalSettings();

                // Execute external action to deal with old save version.
                if (oldVersionAction != null)
                {
                    oldVersionAction(LastRunVersion);
                }
            }

            // Continue loading from save if save version is compatible.
            if (ZoomLevel == default(double))
            {
                setting = LocalServices.LoadLocalSetting("ZoomLevel");
                if (setting is double && (double) setting != default(double))
                {
                    ZoomLevel = (double) setting;
                }
                else
                {
                    ZoomLevel = Globals.DefaultZoomLevel;
                }
            }
            if (MapCenter == null)
            {
                MapCenter = LocalServices.LoadLocalSetting("MapCenter") as GeoCoordinate;
            }

            if (UserPinLog == null)
            {
                setting = LocalServices.LoadLocalSetting("UserPinLog");
                var log = setting as UserPinLog;
                UserPinLog = log ?? new UserPinLog();
            }

            if (TemporaryPins == null)
            {
                setting = LocalServices.LoadLocalSetting("TemporaryPins");
                var pins = setting as ObservableCollection<UserPin>;
                TemporaryPins = pins ?? new ObservableCollection<UserPin>();
            }

            if (EditingUserPin == null)
            {
                setting = LocalServices.LoadLocalSetting("EditingUserPinKey");
                if (setting is Guid)
                {
                    var key = (Guid) setting;
                    EditingUserPin = UserPinLog.Pins.Union(TemporaryPins).FirstOrDefault(p => p.Key == key);
                }
            }

            if (DirectionsCriteria == null)
            {
                setting = LocalServices.LoadLocalSetting(DirectionsCriteriaProperty);
                var criteria = setting as DirectionsCriteria;
                DirectionsCriteria = criteria ?? new DirectionsCriteria();
            }
            if (RouteLocations == null)
            {
                setting = LocalServices.LoadLocalSetting(RouteLocationsPropertyName);
                var locations = setting as IEnumerable<Location>;
                if (locations != null)
                    RouteLocations = locations;
            }
            if (Itineraries == null)
            {
                setting = LocalServices.LoadLocalSetting(ItinerariesPropertyName);
                var items = setting as IEnumerable<ItineraryItem>;
                if (items != null)
                    Itineraries = items;
            }
            if (SearchQuery == null)
            {
                SearchQuery = new SearchQuery {Input = LocalServices.LoadLocalSetting("SearchQuery") as string};
            }

            if (Settings != null) return;
            setting = LocalServices.LoadLocalSetting("Settings");
            if (setting is SettingsViewModel)
            {
                Settings = (SettingsViewModel) LocalServices.LoadLocalSetting("Settings");
            }
            else
            {
                Settings = new SettingsViewModel();
            }
            if (Settings.EnableLocationService)
            {
                GeoWatcher.Start();
            }
            Settings.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName != "EnableLocationService")
                {
                    return;
                }
                if (Settings.EnableLocationService)
                {
                    GeoWatcher.Start();
                }
                else
                {
                    GeoWatcher.Stop();
                    CurrentLocation = null;
                }
            };
        }