// public static String appForceCulture = "qps-PLOC";
public static String appForceCulture = "en";
private static MainViewModel viewModel = null;
- private static SettingsViewModel _settingsViewModel = null;
/// <summary>
/// MainViewModel estático que usan las vistas con el que se van a enlazar.
}
}
- public static SettingsViewModel SettingsViewModel
- {
- get
- {
- // Retrasar la creación del modelo de vista hasta que sea necesario
- if (_settingsViewModel == null)
- _settingsViewModel = new SettingsViewModel();
-
- return _settingsViewModel;
- }
- }
-
/// <summary>
/// Proporcionar acceso sencillo al marco raíz de la aplicación telefónica.
/// </summary>
mc:Ignorable="d"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
-
- <phone:PhoneApplicationPage.Resources>
- <ViewModels:SettingsViewModel x:Key="SettingsViewModelDataSource" d:IsDataSource="True"/>
- </phone:PhoneApplicationPage.Resources>
- <phone:PhoneApplicationPage.FontFamily>
- <StaticResource ResourceKey="PhoneFontFamilyNormal"/>
- </phone:PhoneApplicationPage.FontFamily>
- <phone:PhoneApplicationPage.FontSize>
- <StaticResource ResourceKey="PhoneFontSizeNormal"/>
- </phone:PhoneApplicationPage.FontSize>
- <phone:PhoneApplicationPage.Foreground>
- <StaticResource ResourceKey="PhoneForegroundBrush"/>
- </phone:PhoneApplicationPage.Foreground>
+
+ <phone:PhoneApplicationPage.Resources>
+ <ViewModels:SettingsViewModel x:Key="SettingsViewModelDataSource" d:IsDataSource="True"/>
+ </phone:PhoneApplicationPage.Resources>
+ <phone:PhoneApplicationPage.FontFamily>
+ <StaticResource ResourceKey="PhoneFontFamilyNormal"/>
+ </phone:PhoneApplicationPage.FontFamily>
+ <phone:PhoneApplicationPage.FontSize>
+ <StaticResource ResourceKey="PhoneFontSizeNormal"/>
+ </phone:PhoneApplicationPage.FontSize>
+ <phone:PhoneApplicationPage.Foreground>
+ <StaticResource ResourceKey="PhoneForegroundBrush"/>
+ </phone:PhoneApplicationPage.Foreground>
<!--LayoutRoot es la cuadrícula raíz donde se coloca todo el contenido de la página-->
- <Grid x:Name="LayoutRoot" Background="Transparent" DataContext="{Binding Source={StaticResource SettingsViewModelDataSource}}">
- <!-- Pivot -->
- <phone:Pivot Title="WEATHER INFORMATION">
- <!-- Elemento Pivot uno -->
- <phone:PivotItem Header="settings">
- <Grid VerticalAlignment="Top">
- <Grid.RowDefinitions>
- <RowDefinition Height="*" />
- <RowDefinition Height="*" />
- </Grid.RowDefinitions>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="*" />
- </Grid.ColumnDefinitions>
- <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Vertical" VerticalAlignment="Center">
- <TextBox x:Name="TemperatureUnitsHeader" Text="{Binding LocalizedResources.SettingsTemperatureUnitsHeader, Mode=OneWay, Source={StaticResource LocalizedStrings}}" HorizontalAlignment="Left" Background="Transparent" BorderBrush="Transparent" Foreground="#FFA4A2A2"/>
- <toolkit:ListPicker x:Name="TemperatureUnitsSelection" SelectedIndex="{Binding TemperaruteUnitsSelectionSetting, Mode=TwoWay}">
+ <Grid x:Name="LayoutRoot" Background="Transparent" DataContext="{Binding Source={StaticResource SettingsViewModelDataSource}}">
+ <!-- Pivot -->
+ <phone:Pivot Title="WEATHER INFORMATION">
+ <!-- Elemento Pivot uno -->
+ <phone:PivotItem Header="settings">
+ <Grid VerticalAlignment="Top">
+ <Grid.RowDefinitions>
+ <RowDefinition Height="*" />
+ <RowDefinition Height="*" />
+ </Grid.RowDefinitions>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*" />
+ </Grid.ColumnDefinitions>
+ <StackPanel Grid.Column="0" Grid.Row="0" Orientation="Vertical" VerticalAlignment="Center">
+ <TextBox x:Name="TemperatureUnitsHeader" Text="{Binding LocalizedResources.SettingsTemperatureUnitsHeader, Mode=OneWay, Source={StaticResource LocalizedStrings}}" HorizontalAlignment="Left" Background="Transparent" BorderBrush="Transparent" Foreground="#FFA4A2A2"/>
+ <toolkit:ListPicker x:Name="TemperatureUnitsSelection" SelectedIndex="{Binding Source={StaticResource SettingsViewModelDataSource}, Path=TemperaruteUnitsSelectionSetting, Mode=TwoWay}" SelectionChanged="TemperatureUnitsSelection_SelectionChanged">
<toolkit:ListPickerItem Content="{Binding LocalizedResources.SettingsTemperatureUnitsSelectionFahrenheit, Mode=OneWay, Source={StaticResource LocalizedStrings}}" />
- <toolkit:ListPickerItem Content="{Binding LocalizedResources.SettingsTemperatureUnitsSelectionCentigrade, Mode=OneWay, Source={StaticResource LocalizedStrings}}" />
- </toolkit:ListPicker>
- </StackPanel>
- <StackPanel Grid.Column="0" Grid.Row="1" Orientation="Vertical" VerticalAlignment="Center">
- <TextBox x:Name="LanguageHeader" Text="{Binding LocalizedResources.SettingsLanguageHeader, Mode=OneWay, Source={StaticResource LocalizedStrings}}" HorizontalAlignment="Left" Background="Transparent" BorderBrush="Transparent" Foreground="#FFA4A2A2" />
- <toolkit:ListPicker x:Name="LanguageSelection" SelectedIndex="{Binding LanguageSelectionSetting, Mode=TwoWay}">
- <toolkit:ListPickerItem Content="{Binding LocalizedResources.SettingsLanguageSelectionEnglish, Mode=OneWay, Source={StaticResource LocalizedStrings}}"/>
- <toolkit:ListPickerItem Content="{Binding LocalizedResources.SettingsLanguageSelectionSpanish, Mode=OneWay, Source={StaticResource LocalizedStrings}}"/>
- </toolkit:ListPicker>
- </StackPanel>
- </Grid>
- </phone:PivotItem>
+ <toolkit:ListPickerItem Content="{Binding LocalizedResources.SettingsTemperatureUnitsSelectionCentigrade, Mode=OneWay, Source={StaticResource LocalizedStrings}}" />
+ </toolkit:ListPicker>
+ </StackPanel>
+ <StackPanel Grid.Column="0" Grid.Row="1" Orientation="Vertical" VerticalAlignment="Center">
+ <TextBox x:Name="LanguageHeader" Text="{Binding LocalizedResources.SettingsLanguageHeader, Mode=OneWay, Source={StaticResource LocalizedStrings}}" HorizontalAlignment="Left" Background="Transparent" BorderBrush="Transparent" Foreground="#FFA4A2A2" />
+ <toolkit:ListPicker x:Name="LanguageSelection" SelectedIndex="{Binding Source={StaticResource SettingsViewModelDataSource}, Path=LanguageSelectionSetting, Mode=TwoWay}" SelectionChanged="LanguageSelection_SelectionChanged">
+ <toolkit:ListPickerItem Content="{Binding LocalizedResources.SettingsLanguageSelectionEnglish, Mode=OneWay, Source={StaticResource LocalizedStrings}}"/>
+ <toolkit:ListPickerItem Content="{Binding LocalizedResources.SettingsLanguageSelectionSpanish, Mode=OneWay, Source={StaticResource LocalizedStrings}}"/>
+ </toolkit:ListPicker>
+ </StackPanel>
+ </Grid>
+ </phone:PivotItem>
- <!-- Elemento Pivot dos -->
- <phone:PivotItem Header="notifications">
- <Grid/>
- </phone:PivotItem>
+ <!-- Elemento Pivot dos -->
+ <phone:PivotItem Header="notifications">
+ <Grid/>
+ </phone:PivotItem>
- </phone:Pivot>
- <phone:LongListSelector HorizontalAlignment="Left" Height="100" Margin="825,108,-445,0" VerticalAlignment="Top" Width="100"/>
- </Grid>
+ </phone:Pivot>
+ <phone:LongListSelector HorizontalAlignment="Left" Height="100" Margin="825,108,-445,0" VerticalAlignment="Top" Width="100"/>
+ </Grid>
</phone:PhoneApplicationPage>
\ No newline at end of file
using WeatherInformation.ViewModels;
using System.IO.IsolatedStorage;
using System.Collections;
+using System.Text;
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;
}
- protected override void OnNavigatedTo(NavigationEventArgs e)
+ /// <summary>
+ /// Update temperature units selection when change.
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void TemperatureUnitsSelection_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
+ ListPicker listPicker = sender as ListPicker;
+
+ // TODO: with LINQ :(
+ int index = listPicker.SelectedIndex;
+ var item = listPicker.Items[index];
+ listPicker.SelectedItem = item;
}
- private void TemperatureUnitsSelection_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ /// <summary>
+ /// Update language selection when change.
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void LanguageSelection_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
- IList units = e.AddedItems;
- if (units.Count > 0)
- {
- var selectedUnit = units.Cast<string>().First<string>();
- }
+ ListPicker listPicker = sender as ListPicker;
+
+ // TODO: with LINQ :(
+ int index = listPicker.SelectedIndex;
+ var item = listPicker.Items[index];
+ listPicker.SelectedItem = item;
}
}
}
\ No newline at end of file
/// </summary>
public ObservableCollection<ItemViewModel> ForecastItems { get; private set; }
public ObservableCollection<ItemViewModel> CurrentItems { get; private set; }
- //public string ForecastHeader { get; private set; }
-
- private string _sampleProperty = "Sample Runtime Property Value";
private readonly ServiceParser _serviceParser;
+ "{\"dt\":1398513600,\"temp\":{\"day\":282.75,\"min\":280.61,\"max\":282.75,\"night\":280.61,\"eve\":281.75,\"morn\":281.96},\"pressure\":1007.4,\"humidity\":0,\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"}],\"speed\":9.18,\"deg\":198,\"clouds\":35,\"rain\":0.55}"
+ "]}";
- /// <summary>
- /// Propiedad Sample MainViewModel; 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;
-using System;
+using Microsoft.Phone.Controls;
+using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Windows;
using WeatherInformation.Resources;
namespace WeatherInformation.ViewModels
{
- public class SettingsViewModel : INotifyPropertyChanged
+ public class SettingsViewModel
{
// Settings
private IsolatedStorageSettings settings;
private const string _temperatureUnitsSelectionSettingKeyName = "TemperatureUnitsSelection";
// The default value of ListPicker settings
- private const int _listPickerSettingDefault = 0;
+ private const int _languageSelectionSettingDefault = 0;
+ private const int _temperatureUnitsSelectionSettinDefault = 0;
+
public SettingsViewModel()
{
{
get
{
- return GetValueOrDefault<int>(_languageSelectionSettingKeyName, _listPickerSettingDefault);
+ return GetValueOrDefault<int>(_languageSelectionSettingKeyName, _languageSelectionSettingDefault);
}
set
{
{
get
{
- return GetValueOrDefault<int>(_temperatureUnitsSelectionSettingKeyName, _listPickerSettingDefault);
+ return GetValueOrDefault<int>(_temperatureUnitsSelectionSettingKeyName, _temperatureUnitsSelectionSettinDefault);
}
set
{
{
T value;
+ // You need to add a check to DesignerProperties.IsInDesignTool to that code since accessing
+ // IsolatedStorageSettings in Visual Studio or Expression Blend is invalid.
+ // see: http://stackoverflow.com/questions/7294461/unable-to-determine-application-identity-of-the-caller
+ if (System.ComponentModel.DesignerProperties.IsInDesignTool)
+ {
+ return defaultValue;
+ }
+
// If the key exists, retrieve the value.
if (settings.Contains(Key))
{
{
bool valueChanged = false;
+ // You need to add a check to DesignerProperties.IsInDesignTool to that code since accessing
+ // IsolatedStorageSettings in Visual Studio or Expression Blend is invalid.
+ // see: http://stackoverflow.com/questions/7294461/unable-to-determine-application-identity-of-the-caller
+ if (System.ComponentModel.DesignerProperties.IsInDesignTool)
+ {
+ return false;
+ }
+
// If the key exists
if (settings.Contains(Key))
{
/// </summary>
private void Save()
{
- settings.Save();
- }
-
- public event PropertyChangedEventHandler PropertyChanged;
- private void NotifyPropertyChanged(String propertyName)
- {
- PropertyChangedEventHandler handler = PropertyChanged;
- if (null != handler)
+ // You need to add a check to DesignerProperties.IsInDesignTool to that code since accessing
+ // IsolatedStorageSettings in Visual Studio or Expression Blend is invalid.
+ // see: http://stackoverflow.com/questions/7294461/unable-to-determine-application-identity-of-the-caller
+ if (System.ComponentModel.DesignerProperties.IsInDesignTool)
{
- handler(this, new PropertyChangedEventArgs(propertyName));
+ return;
}
+
+ settings.Save();
}
}
}