Working on WP8 WeatherInformation
authorGustavo Martin <gu.martinm@gmail.com>
Wed, 18 Jun 2014 05:01:02 +0000 (07:01 +0200)
committerGustavo Martin <gu.martinm@gmail.com>
Wed, 18 Jun 2014 05:01:02 +0000 (07:01 +0200)
12 files changed:
WindowsPhone/WeatherInformation/WeatherInformation/App.xaml.cs
WindowsPhone/WeatherInformation/WeatherInformation/MainPage.xaml.cs
WindowsPhone/WeatherInformation/WeatherInformation/MapPage.xaml.cs
WindowsPhone/WeatherInformation/WeatherInformation/SampleData/SettingsViewModelSampleData.xaml
WindowsPhone/WeatherInformation/WeatherInformation/SampleData/TemperatureUnitsViewModelSampleData.xaml [deleted file]
WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml
WindowsPhone/WeatherInformation/WeatherInformation/SettingsPage.xaml.cs
WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/ItemViewModel.cs
WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/MainViewModel.cs
WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/SettingsViewModel.cs
WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/TemperatureUnitsViewModel.cs [deleted file]
WindowsPhone/WeatherInformation/WeatherInformation/WeatherInformation.csproj

index 6081f2a..7b65355 100644 (file)
@@ -15,13 +15,12 @@ namespace WeatherInformation
     {
         private static MainViewModel viewModel = null;
         private static SettingsViewModel _settingsViewModel = null;
-        private static TemperatureUnitsViewModel _temperatureUnitsViewModel = null;
 
         /// <summary>
-        /// ViewModel estático que usan las vistas con el que se van a enlazar.
+        /// MainViewModel estático que usan las vistas con el que se van a enlazar.
         /// </summary>
         /// <returns>Objeto MainViewModel.</returns>
-        public static MainViewModel ViewModel
+        public static MainViewModel MainViewModel
         {
             get
             {
@@ -45,19 +44,6 @@ namespace WeatherInformation
             }
         }
 
-
-        public static TemperatureUnitsViewModel TemperatureUnitsViewModel
-        {
-            get
-            {
-                // Retrasar la creación del modelo de vista hasta que sea necesario
-                if (_temperatureUnitsViewModel == null)
-                    _temperatureUnitsViewModel = new TemperatureUnitsViewModel();
-
-                return _temperatureUnitsViewModel;
-            }
-        }
-
         /// <summary>
         /// Proporcionar acceso sencillo al marco raíz de la aplicación telefónica.
         /// </summary>
@@ -113,9 +99,9 @@ namespace WeatherInformation
         private void Application_Activated(object sender, ActivatedEventArgs e)
         {
             // Asegurarse de que el estado de la aplicación se restaura adecuadamente
-            if (!App.ViewModel.IsDataLoaded)
+            if (!App.MainViewModel.IsDataLoaded)
             {
-                App.ViewModel.LoadData();
+                App.MainViewModel.LoadData();
             }
         }
 
index d07378d..e695bc7 100644 (file)
@@ -19,18 +19,18 @@ namespace WeatherInformation
             InitializeComponent();
 
             // Establecer el contexto de datos del control ListBox control en los datos de ejemplo
-            DataContext = App.ViewModel;
+            DataContext = App.MainViewModel;
 
             // Código de ejemplo para traducir ApplicationBar
             //BuildLocalizedApplicationBar();
         }
 
-        // Cargar datos para los elementos ViewModel
+        // Cargar datos para los elementos MainViewModel
         protected override void OnNavigatedTo(NavigationEventArgs e)
         {
-            if (!App.ViewModel.IsDataLoaded)
+            if (!App.MainViewModel.IsDataLoaded)
             {
-                App.ViewModel.LoadData();
+                App.MainViewModel.LoadData();
             }
         }
 
index 0dde759..3d37029 100644 (file)
@@ -44,18 +44,17 @@ namespace WeatherInformation
                 IsolatedStorageSettings.ApplicationSettings.Save();
             }
 
-            this.GetLocation();
-        }
-
-        private async void GetLocation()
-        {
-
             if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] != true)
             {
                 // The user has opted out of Location.
                 return;
             }
 
+            this.GetLocation();
+        }
+
+        private async void GetLocation()
+        {
             Geolocator geolocator = new Geolocator();
             geolocator.DesiredAccuracyInMeters = 50;
 
index 19b5b85..9e6fa96 100644 (file)
@@ -1,12 +1,14 @@
 <vm:SettingsViewModel
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-    xmlns:vm="clr-namespace:WeatherInformation.ViewModels"
-    SampleProperty="Valor de propiedad Sample Text">
+    xmlns:vm="clr-namespace:WeatherInformation.ViewModels">
 
-    <vm:SettingsViewModel.SettingsItems>
-        <vm:ItemViewModel LineOne="Temperature units" LineTwo="fahrenheit" LineThree="15ºC" LineFour="10ºC" LineFive="/Assets/Tiles/IconicTileMediumLarge.png"/>
-        <vm:ItemViewModel LineOne="Language" LineTwo="spanish" LineThree="16ºC" LineFour="10ºC" LineFive="/Assets/Tiles/IconicTileMediumLarge.png"/>
-    </vm:SettingsViewModel.SettingsItems>
+    <vm:SettingsViewModel.TemperatureUnitsSelection>
+        
+    </vm:SettingsViewModel.TemperatureUnitsSelection>
+    
+    <vm:SettingsViewModel.LanguageSelection>
+       
+    </vm:SettingsViewModel.LanguageSelection>
 
 </vm:SettingsViewModel>
\ No newline at end of file
diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/TemperatureUnitsViewModelSampleData.xaml b/WindowsPhone/WeatherInformation/WeatherInformation/SampleData/TemperatureUnitsViewModelSampleData.xaml
deleted file mode 100644 (file)
index 31a02cc..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<vm:TemperatureUnitsViewModel
-    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-    xmlns:vm="clr-namespace:WeatherInformation.ViewModels"
-    SampleProperty="Valor de propiedad Sample Text">
-
-    <vm:TemperatureUnitsViewModel.TemperatureUnitsItems>
-        <vm:ItemViewModel LineOne="fahrenheit"/>
-        <vm:ItemViewModel LineOne="centigrade"/>
-    </vm:TemperatureUnitsViewModel.TemperatureUnitsItems>
-
-</vm:TemperatureUnitsViewModel>
\ No newline at end of file
index f75296e..599185a 100644 (file)
     Foreground="{StaticResource PhoneForegroundBrush}"
     SupportedOrientations="PortraitOrLandscape"  Orientation="Portrait"
     shell:SystemTray.IsVisible="True">
+       <phone:PhoneApplicationPage.Resources>
+               <DataTemplate x:Key="StringTemplate">
+                       <StackPanel>
+                               <TextBlock Text="{Binding Mode=OneWay}"/>
+                       </StackPanel>
+               </DataTemplate>
+               <DataTemplate x:Key="StringTemplate1">
+                       <StackPanel>
+                               <TextBlock Text="{Binding Mode=OneWay}"/>
+                       </StackPanel>
+               </DataTemplate>
+       </phone:PhoneApplicationPage.Resources>
 
     <!--LayoutRoot es la cuadrícula raíz donde se coloca todo el contenido de la página-->
     <Grid x:Name="LayoutRoot" Background="Transparent">
                     </Grid.ColumnDefinitions>
                     <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Vertical">
                         <TextBox x:Name="TemperatureUnitsText" Text="{Binding LocalizedResources.TemperatureSettingsText, Mode=OneWay, Source={StaticResource LocalizedStrings}}" HorizontalAlignment="Left" Background="Transparent" BorderBrush="Transparent" Foreground="#FFA4A2A2" />
-                        <toolkit:ListPicker x:Name="ListUnitsSelection">
-                            <toolkit:ListPickerItem x:Name="fahrenheit" Content="fahrenheit" Background="Transparent" />
-                            <toolkit:ListPickerItem x:Name="centigrade" Content="centigrade" />
+                        <toolkit:ListPicker x:Name="TemperatureUnitsSelection" ItemsSource="{Binding TemperatureUnitsSelection}">
                         </toolkit:ListPicker>
                     </StackPanel>
                     <StackPanel Grid.Column="0" Grid.Row="1" Orientation="Vertical" VerticalAlignment="Center">
                         <TextBox x:Name="LanguageTextBox" Text="{Binding LocalizedResources.LanguageSettingsText, Mode=OneWay, Source={StaticResource LocalizedStrings}}" HorizontalAlignment="Left" Background="Transparent" BorderBrush="Transparent" Foreground="#FFA4A2A2" />
-                        <toolkit:ListPicker x:Name="LanguageSelection">
-                            <toolkit:ListPickerItem x:Name="english" Content="english" Background="Transparent" />
-                            <toolkit:ListPickerItem x:Name="spanish" Content="spanish" />
+                        <toolkit:ListPicker x:Name="LanguageSelection" ItemsSource="{Binding LanguageSelection}">
                         </toolkit:ListPicker>
                     </StackPanel>
                 </Grid>
index df7243f..61a8cb7 100644 (file)
@@ -8,15 +8,21 @@ using System.Windows.Navigation;
 using Microsoft.Phone.Controls;
 using Microsoft.Phone.Shell;
 using WeatherInformation.ViewModels;
+using System.IO.IsolatedStorage;
 
 namespace WeatherInformation
 {
     public partial class SettingsPage : PhoneApplicationPage
     {
+        // Our settings
+        private IsolatedStorageSettings _settings;
+
         public SettingsPage()
         {
             InitializeComponent();
 
+            _settings = IsolatedStorageSettings.ApplicationSettings;
+
             // Establecer el contexto de datos del control ListBox control en los datos de ejemplo
             DataContext = App.SettingsViewModel;
         }
index 7988bde..6b4349c 100644 (file)
@@ -14,7 +14,7 @@ namespace WeatherInformation.ViewModels
     {
         private string _lineOne;
         /// <summary>
-        /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace.
+        /// Propiedad Sample MainViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace.
         /// </summary>
         /// <returns></returns>
         public string LineOne
@@ -35,7 +35,7 @@ namespace WeatherInformation.ViewModels
 
         private string _lineTwo;
         /// <summary>
-        /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace.
+        /// Propiedad Sample MainViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace.
         /// </summary>
         /// <returns></returns>
         public string LineTwo
@@ -56,7 +56,7 @@ namespace WeatherInformation.ViewModels
 
         private string _lineThree;
         /// <summary>
-        /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace.
+        /// Propiedad Sample MainViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace.
         /// </summary>
         /// <returns></returns>
         public string LineThree
@@ -77,7 +77,7 @@ namespace WeatherInformation.ViewModels
 
         private string _lineFour;
         /// <summary>
-        /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace.
+        /// Propiedad Sample MainViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace.
         /// </summary>
         /// <returns></returns>
         public string LineFour
@@ -98,7 +98,7 @@ namespace WeatherInformation.ViewModels
 
         private string _lineFive;
         /// <summary>
-        /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace.
+        /// Propiedad Sample MainViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace.
         /// </summary>
         /// <returns></returns>
         public string LineFive
index 3deea79..d801a70 100644 (file)
@@ -54,7 +54,7 @@ namespace WeatherInformation.ViewModels
     + "]}";
 
         /// <summary>
-        /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace
+        /// Propiedad Sample MainViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace
         /// </summary>
         /// <returns></returns>
         public string SampleProperty
index 9a185ea..6e82502 100644 (file)
@@ -12,31 +12,12 @@ namespace WeatherInformation.ViewModels
     {
         public SettingsViewModel()
         {
-            this.SettingsItems = new ObservableCollection<ItemViewModel>();
+            this.TemperatureUnitsSelection = new List<string>();
+            this.LanguageSelection = new List<string>();
         }
 
-        private string _sampleProperty = "Sample Runtime Property Value";
-
-        public ObservableCollection<ItemViewModel> SettingsItems { get; private set; }
-        /// <summary>
-        /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace
-        /// </summary>
-        /// <returns></returns>
-        public string SampleProperty
-        {
-            get
-            {
-                return _sampleProperty;
-            }
-            set
-            {
-                if (value != _sampleProperty)
-                {
-                    _sampleProperty = value;
-                    NotifyPropertyChanged("SampleProperty");
-                }
-            }
-        }
+        public List<string> TemperatureUnitsSelection { get; private set; }
+        public List<string> LanguageSelection { get; private set; }
 
         public bool IsDataLoaded
         {
@@ -45,22 +26,18 @@ namespace WeatherInformation.ViewModels
         }
 
         /// <summary>
-        /// Crear y agregar unos pocos objetos ItemViewModel a la colección Items.
+        /// Crear y agregar unos pocos objetos a la colección Items.
         /// </summary>
         public void LoadData()
         {
-                // TODO: How to do the same using StaticResources? :/
-                this.SettingsItems.Add(new ItemViewModel()
-                {
-                    LineOne = "Temperature units",
-                    LineTwo = "fahrenheit"
-                });
-                this.SettingsItems.Add(new ItemViewModel()
-                {
-                    LineOne = "Language",
-                    LineTwo = "spanish"
-                });
-
+            // TODO: How to do the same using StaticResources? :/ What the translator should do with this :(
+            // There must be some way to refernce static resources from here or something like that, otherwise
+            // the translator is going to complain A LOT!
+            TemperatureUnitsSelection.Add("fahrenheit");
+            TemperatureUnitsSelection.Add("centigrade");
+
+            LanguageSelection.Add("english");
+            LanguageSelection.Add("spanish");
 
             this.IsDataLoaded = true;
         }
diff --git a/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/TemperatureUnitsViewModel.cs b/WindowsPhone/WeatherInformation/WeatherInformation/ViewModels/TemperatureUnitsViewModel.cs
deleted file mode 100644 (file)
index f316cbf..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace WeatherInformation.ViewModels
-{
-    public class TemperatureUnitsViewModel : INotifyPropertyChanged
-    {
-        public TemperatureUnitsViewModel()
-        {
-            this.TemperatureUnitsItems = new ObservableCollection<ItemViewModel>();
-        }
-
-        private string _sampleProperty = "Sample Runtime Property Value";
-
-        public ObservableCollection<ItemViewModel> TemperatureUnitsItems { get; private set; }
-        /// <summary>
-        /// Propiedad Sample ViewModel; esta propiedad se usa en la vista para mostrar su valor mediante un enlace
-        /// </summary>
-        /// <returns></returns>
-        public string SampleProperty
-        {
-            get
-            {
-                return _sampleProperty;
-            }
-            set
-            {
-                if (value != _sampleProperty)
-                {
-                    _sampleProperty = value;
-                    NotifyPropertyChanged("SampleProperty");
-                }
-            }
-        }
-
-        public bool IsDataLoaded
-        {
-            get;
-            private set;
-        }
-
-        /// <summary>
-        /// Crear y agregar unos pocos objetos ItemViewModel a la colección Items.
-        /// </summary>
-        public void LoadData()
-        {
-                // TODO: How to do the same using StaticResources? :/
-                this.TemperatureUnitsItems.Add(new ItemViewModel()
-                {
-                    LineOne = "fahrenheit"
-                });
-                this.TemperatureUnitsItems.Add(new ItemViewModel()
-                {
-                    LineOne = "centigrade"
-                });
-
-
-            this.IsDataLoaded = true;
-        }
-
-        public event PropertyChangedEventHandler PropertyChanged;
-        private void NotifyPropertyChanged(String propertyName)
-        {
-            PropertyChangedEventHandler handler = PropertyChanged;
-            if (null != handler)
-            {
-                handler(this, new PropertyChangedEventArgs(propertyName));
-            }
-        }
-    }
-}
index e5f2f97..0b14d44 100644 (file)
@@ -25,6 +25,7 @@
     <ValidateXaml>true</ValidateXaml>
     <MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
     <ThrowErrorsInValidation>true</ThrowErrorsInValidation>
+    <ExpressionBlendVersion>12.0.41212.0</ExpressionBlendVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
     </Compile>
     <Compile Include="ViewModels\ItemViewModel.cs" />
     <Compile Include="ViewModels\MainViewModel.cs" />
-    <Compile Include="ViewModels\TemperatureUnitsViewModel.cs" />
     <Compile Include="ViewModels\SettingsViewModel.cs" />
   </ItemGroup>
   <ItemGroup>
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </DesignData>
-    <DesignData Include="SampleData\TemperatureUnitsViewModelSampleData.xaml">
-      <Generator>MSBuild:Compile</Generator>
-      <SubType>Designer</SubType>
-    </DesignData>
     <Page Include="SettingsPage.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>