├── images
├── WPF.png
└── weatherapp.png
├── src
├── WeatherApp
│ ├── WeatherApp.WPF
│ │ ├── Images
│ │ │ ├── sun.png
│ │ │ ├── cloud.png
│ │ │ ├── moon.png
│ │ │ ├── rain.png
│ │ │ ├── reload.png
│ │ │ ├── rain-background.jpg
│ │ │ ├── sun-background.jpg
│ │ │ └── clouds-background.jpg
│ │ ├── App.xaml.cs
│ │ ├── Properties
│ │ │ ├── Settings.settings
│ │ │ ├── Settings.Designer.cs
│ │ │ ├── AssemblyInfo.cs
│ │ │ ├── Resources.Designer.cs
│ │ │ └── Resources.resx
│ │ ├── MainWindow.xaml.cs
│ │ ├── App.config
│ │ ├── packages.config
│ │ ├── MainWindow.xaml
│ │ ├── App.xaml
│ │ ├── OpenTK.dll.config
│ │ └── WeatherApp.WPF.csproj
│ └── WeatherApp
│ │ ├── AppSettings.cs
│ │ ├── Views
│ │ ├── Templates
│ │ │ ├── WeatherItemTemplate.xaml.cs
│ │ │ └── WeatherItemTemplate.xaml
│ │ ├── CustomNavigationPage.xaml
│ │ ├── CustomNavigationPage.xaml.cs
│ │ ├── WeatherView.xaml.cs
│ │ └── WeatherView.xaml
│ │ ├── WeatherApp.csproj
│ │ ├── App.xaml.cs
│ │ ├── Converters
│ │ ├── InverseBoolConverter.cs
│ │ ├── BackgroundConverter.cs
│ │ └── IconConverter.cs
│ │ ├── App.xaml
│ │ ├── ViewModels
│ │ └── WeatherViewModel.cs
│ │ ├── Services
│ │ └── WeatherService.cs
│ │ ├── Models
│ │ └── Weather.cs
│ │ └── Controls
│ │ └── HorizontalList
│ │ └── HorizontalList.cs
└── WeatherApp.sln
├── .gitattributes
├── README.md
└── .gitignore
/images/WPF.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuarezruiz/xamarin-forms-wpf-weather-sample/HEAD/images/WPF.png
--------------------------------------------------------------------------------
/images/weatherapp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuarezruiz/xamarin-forms-wpf-weather-sample/HEAD/images/weatherapp.png
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Images/sun.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuarezruiz/xamarin-forms-wpf-weather-sample/HEAD/src/WeatherApp/WeatherApp.WPF/Images/sun.png
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Images/cloud.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuarezruiz/xamarin-forms-wpf-weather-sample/HEAD/src/WeatherApp/WeatherApp.WPF/Images/cloud.png
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Images/moon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuarezruiz/xamarin-forms-wpf-weather-sample/HEAD/src/WeatherApp/WeatherApp.WPF/Images/moon.png
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Images/rain.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuarezruiz/xamarin-forms-wpf-weather-sample/HEAD/src/WeatherApp/WeatherApp.WPF/Images/rain.png
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Windows;
2 |
3 | namespace WeatherApp.WPF
4 | {
5 | public partial class App : Application
6 | {
7 | }
8 | }
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Images/reload.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuarezruiz/xamarin-forms-wpf-weather-sample/HEAD/src/WeatherApp/WeatherApp.WPF/Images/reload.png
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Images/rain-background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuarezruiz/xamarin-forms-wpf-weather-sample/HEAD/src/WeatherApp/WeatherApp.WPF/Images/rain-background.jpg
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Images/sun-background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuarezruiz/xamarin-forms-wpf-weather-sample/HEAD/src/WeatherApp/WeatherApp.WPF/Images/sun-background.jpg
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Images/clouds-background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jsuarezruiz/xamarin-forms-wpf-weather-sample/HEAD/src/WeatherApp/WeatherApp.WPF/Images/clouds-background.jpg
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/AppSettings.cs:
--------------------------------------------------------------------------------
1 | namespace WeatherApp
2 | {
3 | public class AppSettings
4 | {
5 | public static string Location = "Sevilla";
6 | public static bool IsImperial = false;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Views/Templates/WeatherItemTemplate.xaml.cs:
--------------------------------------------------------------------------------
1 | using Xamarin.Forms;
2 |
3 | namespace WeatherApp.Views.Templates
4 | {
5 | public partial class WeatherItemTemplate : ContentView
6 | {
7 | public WeatherItemTemplate()
8 | {
9 | InitializeComponent();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using Xamarin.Forms.Platform.WPF;
2 |
3 | namespace WeatherApp.WPF
4 | {
5 | public partial class MainWindow : FormsApplicationPage
6 | {
7 | public MainWindow()
8 | {
9 | InitializeComponent();
10 | Xamarin.Forms.Forms.Init();
11 | LoadApplication(new WeatherApp.App());
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Views/CustomNavigationPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Views/CustomNavigationPage.xaml.cs:
--------------------------------------------------------------------------------
1 | using Xamarin.Forms;
2 |
3 | namespace WeatherApp.Views
4 | {
5 | public partial class CustomNavigationPage : NavigationPage
6 | {
7 | public CustomNavigationPage() : base()
8 | {
9 | InitializeComponent();
10 | }
11 |
12 | public CustomNavigationPage(Page root) : base(root)
13 | {
14 | InitializeComponent();
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/WeatherApp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | *.xaml
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Views/WeatherView.xaml.cs:
--------------------------------------------------------------------------------
1 | using WeatherApp.ViewModels;
2 | using Xamarin.Forms;
3 | using Xamarin.Forms.Xaml;
4 |
5 | namespace WeatherApp.Views
6 | {
7 | public partial class WeatherView : ContentPage
8 | {
9 | public WeatherView()
10 | {
11 | InitializeComponent();
12 |
13 | BindingContext = new WeatherViewModel();
14 | }
15 |
16 | protected override async void OnAppearing()
17 | {
18 | if (BindingContext is WeatherViewModel)
19 | {
20 | await ((WeatherViewModel)BindingContext).GetWeatherAsync();
21 | }
22 |
23 | base.OnAppearing();
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using WeatherApp.Views;
2 | using Xamarin.Forms;
3 |
4 | namespace WeatherApp
5 | {
6 | public partial class App : Application
7 | {
8 | public App()
9 | {
10 | InitializeComponent();
11 |
12 | MainPage = new CustomNavigationPage(new WeatherView());
13 | }
14 |
15 | protected override void OnStart()
16 | {
17 | // Handle when your app starts
18 | }
19 |
20 | protected override void OnSleep()
21 | {
22 | // Handle when your app sleeps
23 | }
24 |
25 | protected override void OnResume()
26 | {
27 | // Handle when your app resumes
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Converters/InverseBoolConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using Xamarin.Forms;
4 |
5 | namespace WeatherApp.Converters
6 | {
7 | public class InverseBoolConverter : IValueConverter
8 | {
9 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10 | {
11 | if (!(value is bool))
12 | {
13 | throw new InvalidOperationException("The target must be a boolean");
14 | }
15 |
16 | return !(bool)value;
17 | }
18 |
19 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
20 | {
21 | return null;
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/App.xaml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 | #353186
11 | #FFFFFF
12 | #000000
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Este código fue generado por una herramienta.
4 | // Versión de runtime:4.0.30319.42000
5 | //
6 | // Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si
7 | // se vuelve a generar el código.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WeatherApp.WPF.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.8.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/App.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Views/Templates/WeatherItemTemplate.xaml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
19 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
29 |
33 |
37 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/OpenTK.dll.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Converters/BackgroundConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using Xamarin.Forms;
4 |
5 | namespace WeatherApp.Converters
6 | {
7 | public class BackgroundConverter : IValueConverter
8 | {
9 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10 | {
11 | if (value == null)
12 | return string.Empty;
13 |
14 | var condition = value.ToString();
15 |
16 | if (condition.Contains("cloud"))
17 | {
18 | if (Device.RuntimePlatform == Device.WPF)
19 | return "Images/clouds-background.jpg";
20 | else if (Device.RuntimePlatform == Device.UWP)
21 | return "Assets/clouds-background.jpg";
22 | else
23 | return "clouds-background.jpg";
24 | }
25 | else if (condition.Contains("rain"))
26 | {
27 | if (Device.RuntimePlatform == Device.WPF)
28 | return "Images/rain-background.jpg";
29 | else if (Device.RuntimePlatform == Device.UWP)
30 | return "Assets/rain-background.jpg";
31 | else
32 | return "rain-background.jpg";
33 | }
34 | else if (condition.Contains("sun") || (condition.Contains("clear sky")))
35 | {
36 | if (Device.RuntimePlatform == Device.WPF)
37 | return "Images/sun-background.jpg";
38 | else if (Device.RuntimePlatform == Device.UWP)
39 | return "Assets/sun-background.jpg";
40 | else
41 | return "sun-background.jpg";
42 | }
43 | else
44 | return string.Empty;
45 | }
46 |
47 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
48 | {
49 | return null;
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Weather
2 |
3 | **Weather** is a Xamarin.Forms **WPF backend** application that makes use [OpenWeatherMap.org API](https://openweathermap.org/api), to demonstrate the possibilities of the new backend making use of a great variety of functionality.
4 |
5 |
6 |
7 | Do you want to see the [progress](https://github.com/mohachouch/forms-wpf-progress) of the Xamarin.Forms WPF backend?
8 |
9 |
10 |
11 |
12 |
13 | ## Xamarin.Forms App
14 |
15 | [Xamarin.Forms](https://www.xamarin.com/forms) allows you to build native UIs for iOS, Android, **Windows**, macOS and Linux from a single, shared codebase. You can dive into mobile development with Xamarin.Forms by following our [free self-guided learning](https://university.xamarin.com/classes/track/self-guided) from Xamarin University. This project exercises the following patterns and features:
16 |
17 | * Xamarin.Forms
18 | * [XAML UI](https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-basics/)
19 | * Converters
20 | * Custom Controls
21 | * [Data Binding](https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-basics/data_binding_basics/)
22 | * [MVVM](https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-basics/data_bindings_to_mvvm/)
23 | * [Styles](https://developer.xamarin.com/guides/xamarin-forms/user-interface/styles/)
24 |
25 | ## Requirements
26 |
27 | * [Visual Studio __2015__](https://www.visualstudio.com/en-us/products/vs-2015-product-editions.aspx) Update 3 (14.0 or higher) to compile C# 6 language features (or Visual Studio MacOS)
28 | * Xamarin add-ons for Visual Studio 3.2.1.64 or higher (available via the Visual Studio installer)
29 | * __Visual Studio Community Edition is fully supported!__
30 |
31 | ## Setup
32 |
33 | **Download** or clone the repository. This is a solution with two projects.
34 |
35 | **Rebuild** the solution to get all neccesary **NuGet** packages.
36 |
37 | Access to **AppSettings.cs** file available in the .NET Standard library to introduce your city.
38 |
39 | Enjoy!
40 |
41 | ## Licenses
42 |
43 | This project is based on [MyWeather.Forms](https://github.com/jamesmontemagno/MyWeather.Forms) by James Montemagno.
44 |
45 | ## Clean and Rebuild
46 |
47 | If you see build issues when pulling updates from the repo, try cleaning and rebuilding the solution.
48 |
49 | ## Copyright and license
50 |
51 | Code released under the [MIT license](https://opensource.org/licenses/MIT).
52 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Converters/IconConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using Xamarin.Forms;
4 |
5 | namespace WeatherApp.Converters
6 | {
7 | public class IconConverter : IValueConverter
8 | {
9 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10 | {
11 | if (value == null)
12 | return string.Empty;
13 |
14 | var iconType = value.ToString();
15 |
16 | switch(iconType)
17 | {
18 | case "01n":
19 | if(Device.RuntimePlatform == Device.WPF)
20 | return "Images/moon.png";
21 | else if (Device.RuntimePlatform == Device.UWP)
22 | return "Assets/moon.png";
23 | else
24 | return "moon.png";
25 | case "01d":
26 | if (Device.RuntimePlatform == Device.WPF)
27 | return "Images/sun.png";
28 | else if (Device.RuntimePlatform == Device.UWP)
29 | return "Assets/sun.png";
30 | else
31 | return "sun.png";
32 | case "02n":
33 | case "02d":
34 | case "04d":
35 | if (Device.RuntimePlatform == Device.WPF)
36 | return "Images/cloud.png";
37 | else if (Device.RuntimePlatform == Device.UWP)
38 | return "Assets/cloud.png";
39 | else
40 | return "cloud.png";
41 | case "10d":
42 | if (Device.RuntimePlatform == Device.WPF)
43 | return "Images/rain.png";
44 | else if (Device.RuntimePlatform == Device.UWP)
45 | return "Assets/rain.png";
46 | else
47 | return "rain.png";
48 | default:
49 | if (Device.RuntimePlatform == Device.WPF)
50 | return "Images/cloud.png";
51 | else if (Device.RuntimePlatform == Device.UWP)
52 | return "Assets/cloud.png";
53 | else
54 | return "cloud.png";
55 | }
56 | }
57 |
58 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
59 | {
60 | return null;
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("WeatherApp.WPF")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("WeatherApp.WPF")]
15 | [assembly: AssemblyCopyright("Copyright © 2017")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/ViewModels/WeatherViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Threading.Tasks;
4 | using System.Windows.Input;
5 | using WeatherApp.Models;
6 | using WeatherApp.Services;
7 | using Xamarin.Forms;
8 |
9 | namespace WeatherApp.ViewModels
10 | {
11 | public class WeatherViewModel : BindableObject
12 | {
13 | private bool _isBusy;
14 | private string _temp;
15 | private string _condition;
16 | private WeatherForecastRoot _forecast;
17 | private ICommand _reloadCommand;
18 |
19 | public bool IsBusy
20 | {
21 | get { return _isBusy; }
22 | set
23 | {
24 | _isBusy = value;
25 | OnPropertyChanged();
26 | }
27 | }
28 |
29 | public string Temp
30 | {
31 | get { return _temp; }
32 | set
33 | {
34 | _temp = value;
35 | OnPropertyChanged();
36 | }
37 | }
38 |
39 | public string Condition
40 | {
41 | get { return _condition; }
42 | set
43 | {
44 | _condition = value;
45 | OnPropertyChanged();
46 | }
47 | }
48 |
49 | public WeatherForecastRoot Forecast
50 | {
51 | get { return _forecast; }
52 | set
53 | {
54 | _forecast = value;
55 | OnPropertyChanged();
56 | }
57 | }
58 |
59 | public ICommand ReloadCommand =>
60 | _reloadCommand ??
61 | (_reloadCommand = new Command(async () => await GetWeatherAsync()));
62 |
63 | public async Task GetWeatherAsync()
64 | {
65 | if (IsBusy)
66 | return;
67 |
68 | IsBusy = true;
69 | try
70 | {
71 | WeatherRoot weatherRoot = null;
72 | var units = AppSettings.IsImperial ? Units.Imperial : Units.Metric;
73 | weatherRoot = await WeatherService.Instance.GetWeatherAsync(AppSettings.Location.Trim(), units);
74 | Forecast = await WeatherService.Instance.GetForecast(weatherRoot.CityId, units);
75 | var unit = AppSettings.IsImperial ? "F" : "C";
76 | Temp = $"{weatherRoot?.MainWeather?.Temperature ?? 0}°{unit}";
77 | Condition = $"{weatherRoot.Name}: {weatherRoot?.Weather?[0]?.Description ?? string.Empty}";
78 | }
79 | catch (Exception ex)
80 | {
81 | Temp = "Unable to get Weather";
82 | Debug.WriteLine(ex.Message);
83 | }
84 | finally
85 | {
86 | IsBusy = false;
87 | }
88 | }
89 | }
90 | }
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Services/WeatherService.cs:
--------------------------------------------------------------------------------
1 | using System.Net.Http;
2 | using System.Threading.Tasks;
3 | using WeatherApp.Models;
4 | using static Newtonsoft.Json.JsonConvert;
5 |
6 | namespace WeatherApp.Services
7 | {
8 | public enum Units
9 | {
10 | Imperial,
11 | Metric
12 | }
13 |
14 | public class WeatherService
15 | {
16 | const string WeatherCoordinatesUri = "http://api.openweathermap.org/data/2.5/weather?lat={0}&lon={1}&units={2}&appid=fc9f6c524fc093759cd28d41fda89a1b";
17 | const string WeatherCityUri = "http://api.openweathermap.org/data/2.5/weather?q={0}&units={1}&appid=fc9f6c524fc093759cd28d41fda89a1b";
18 | const string ForecaseUri = "http://api.openweathermap.org/data/2.5/forecast?id={0}&units={1}&appid=fc9f6c524fc093759cd28d41fda89a1b";
19 |
20 | private static WeatherService _instance;
21 |
22 | public static WeatherService Instance
23 | {
24 | get
25 | {
26 | if (_instance == null)
27 | _instance = new WeatherService();
28 |
29 | return _instance;
30 | }
31 | }
32 |
33 | public async Task GetWeatherAsync(double latitude, double longitude, Units units = Units.Imperial)
34 | {
35 | using (var client = new HttpClient())
36 | {
37 | var url = string.Format(WeatherCoordinatesUri, latitude, longitude, units.ToString().ToLower());
38 | var json = await client.GetStringAsync(url);
39 |
40 | if (string.IsNullOrWhiteSpace(json))
41 | return null;
42 |
43 | return DeserializeObject(json);
44 | }
45 |
46 | }
47 |
48 | public async Task GetWeatherAsync(string city, Units units = Units.Imperial)
49 | {
50 | using (var client = new HttpClient())
51 | {
52 | var url = string.Format(WeatherCityUri, city, units.ToString().ToLower());
53 | var json = await client.GetStringAsync(url);
54 |
55 | if (string.IsNullOrWhiteSpace(json))
56 | return null;
57 |
58 | return DeserializeObject(json);
59 | }
60 |
61 | }
62 |
63 | public async Task GetForecast(int id, Units units = Units.Imperial)
64 | {
65 | using (var client = new HttpClient())
66 | {
67 | var url = string.Format(ForecaseUri, id, units.ToString().ToLower());
68 | var json = await client.GetStringAsync(url);
69 |
70 | if (string.IsNullOrWhiteSpace(json))
71 | return null;
72 |
73 | return DeserializeObject(json);
74 | }
75 |
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Este código fue generado por una herramienta.
4 | // Versión de runtime:4.0.30319.42000
5 | //
6 | // Los cambios en este archivo podrían causar un comportamiento incorrecto y se perderán si
7 | // se vuelve a generar el código.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WeatherApp.WPF.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// Clase de recurso fuertemente tipado, para buscar cadenas traducidas, etc.
17 | ///
18 | // StronglyTypedResourceBuilder generó automáticamente esta clase
19 | // a través de una herramienta como ResGen o Visual Studio.
20 | // Para agregar o quitar un miembro, edite el archivo .ResX y, a continuación, vuelva a ejecutar ResGen
21 | // con la opción /str o recompile su proyecto de VS.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Devuelve la instancia de ResourceManager almacenada en caché utilizada por esta clase.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WeatherApp.WPF.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Reemplaza la propiedad CurrentUICulture del subproceso actual para todas las
51 | /// búsquedas de recursos mediante esta clase de recurso fuertemente tipado.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Views/WeatherView.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
14 |
15 |
20 |
21 |
26 |
27 |
28 |
29 |
30 |
34 |
35 |
36 |
38 |
41 |
42 |
43 |
44 |
45 |
49 |
50 |
51 |
52 |
53 |
54 |
59 |
61 |
64 |
65 |
69 |
70 |
72 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Models/Weather.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 |
5 | namespace WeatherApp.Models
6 | {
7 | public class Coord
8 | {
9 | [JsonProperty("lon")]
10 | public double Longitude { get; set; } = 0;
11 |
12 | [JsonProperty("lat")]
13 | public double Latitude { get; set; } = 0;
14 | }
15 |
16 | public class Sys
17 | {
18 |
19 | [JsonProperty("country")]
20 | public string Country { get; set; } = string.Empty;
21 | }
22 |
23 | public class Weather
24 | {
25 | [JsonProperty("id")]
26 | public int Id { get; set; } = 0;
27 |
28 | [JsonProperty("main")]
29 | public string Main { get; set; } = string.Empty;
30 |
31 | [JsonProperty("description")]
32 | public string Description { get; set; } = string.Empty;
33 |
34 | [JsonProperty("icon")]
35 | public string Icon { get; set; } = string.Empty;
36 | }
37 |
38 | public class Main
39 | {
40 | [JsonProperty("temp")]
41 | public double Temperature { get; set; } = 0;
42 | [JsonProperty("pressure")]
43 | public double Pressure { get; set; } = 0;
44 |
45 | [JsonProperty("humidity")]
46 | public double Humidity { get; set; } = 0;
47 | [JsonProperty("temp_min")]
48 | public double MinTemperature { get; set; } = 0;
49 |
50 | [JsonProperty("temp_max")]
51 | public double MaxTemperature { get; set; } = 0;
52 | }
53 |
54 | public class Wind
55 | {
56 | [JsonProperty("speed")]
57 | public double Speed { get; set; } = 0;
58 |
59 | [JsonProperty("deg")]
60 | public double WindDirectionDegrees { get; set; } = 0;
61 |
62 | }
63 |
64 | public class Clouds
65 | {
66 |
67 | [JsonProperty("all")]
68 | public int CloudinessPercent { get; set; } = 0;
69 | }
70 |
71 | public class WeatherRoot
72 | {
73 | [JsonProperty("coord")]
74 | public Coord Coordinates { get; set; } = new Coord();
75 |
76 | [JsonProperty("sys")]
77 | public Sys System { get; set; } = new Sys();
78 |
79 | [JsonProperty("weather")]
80 | public List Weather { get; set; } = new List();
81 |
82 | [JsonProperty("main")]
83 | public Main MainWeather { get; set; } = new Main();
84 |
85 | [JsonProperty("wind")]
86 | public Wind Wind { get; set; } = new Wind();
87 |
88 | [JsonProperty("clouds")]
89 | public Clouds Clouds { get; set; } = new Clouds();
90 |
91 | [JsonProperty("id")]
92 | public int CityId { get; set; } = 0;
93 |
94 | [JsonProperty("name")]
95 | public string Name { get; set; } = string.Empty;
96 |
97 | [JsonProperty("dt_txt")]
98 | public string Date { get; set; } = string.Empty;
99 |
100 | [JsonIgnore]
101 | public string DisplayDate => DateTime.Parse(Date).Hour.ToString();
102 | [JsonIgnore]
103 | public string DisplayTemp => $"{MainWeather?.Temperature ?? 0}° {Weather?[0]?.Main ?? string.Empty}";
104 | [JsonIgnore]
105 | public string DisplayIcon => $"http://openweathermap.org/img/w/{Weather?[0]?.Icon}.png";
106 | [JsonIgnore]
107 | public string Icon => Weather?[0]?.Icon;
108 | }
109 |
110 | public class WeatherForecastRoot
111 | {
112 | [JsonProperty("city")]
113 | public City City { get; set; }
114 | [JsonProperty("cod")]
115 | public string Vod { get; set; }
116 | [JsonProperty("message")]
117 | public double Message { get; set; }
118 | [JsonProperty("cnt")]
119 | public int Cnt { get; set; }
120 | [JsonProperty("list")]
121 | public List Items { get; set; }
122 |
123 | }
124 |
125 | public class City
126 | {
127 | [JsonProperty("id")]
128 | public int Id { get; set; }
129 | [JsonProperty("name")]
130 | public string Name { get; set; }
131 | [JsonProperty("coord")]
132 | public Coord Coord { get; set; }
133 | [JsonProperty("country")]
134 | public string Country { get; set; }
135 | [JsonProperty("population")]
136 | public int Population { get; set; }
137 | [JsonProperty("sys")]
138 | public Sys Sys { get; set; }
139 | }
140 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 | *.VC.VC.opendb
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 | *.sap
91 |
92 | # TFS 2012 Local Workspace
93 | $tf/
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 | *.DotSettings.user
102 |
103 | # JustCode is a .NET coding add-in
104 | .JustCode
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | _NCrunch_*
114 | .*crunch*.local.xml
115 | nCrunchTemp_*
116 |
117 | # MightyMoose
118 | *.mm.*
119 | AutoTest.Net/
120 |
121 | # Web workbench (sass)
122 | .sass-cache/
123 |
124 | # Installshield output folder
125 | [Ee]xpress/
126 |
127 | # DocProject is a documentation generator add-in
128 | DocProject/buildhelp/
129 | DocProject/Help/*.HxT
130 | DocProject/Help/*.HxC
131 | DocProject/Help/*.hhc
132 | DocProject/Help/*.hhk
133 | DocProject/Help/*.hhp
134 | DocProject/Help/Html2
135 | DocProject/Help/html
136 |
137 | # Click-Once directory
138 | publish/
139 |
140 | # Publish Web Output
141 | *.[Pp]ublish.xml
142 | *.azurePubxml
143 | # TODO: Comment the next line if you want to checkin your web deploy settings
144 | # but database connection strings (with potential passwords) will be unencrypted
145 | *.pubxml
146 | *.publishproj
147 |
148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
149 | # checkin your Azure Web App publish settings, but sensitive information contained
150 | # in these scripts will be unencrypted
151 | PublishScripts/
152 |
153 | # NuGet Packages
154 | *.nupkg
155 | # The packages folder can be ignored because of Package Restore
156 | **/packages/*
157 | # except build/, which is used as an MSBuild target.
158 | !**/packages/build/
159 | # Uncomment if necessary however generally it will be regenerated when needed
160 | #!**/packages/repositories.config
161 | # NuGet v3's project.json files produces more ignoreable files
162 | *.nuget.props
163 | *.nuget.targets
164 |
165 | # Microsoft Azure Build Output
166 | csx/
167 | *.build.csdef
168 |
169 | # Microsoft Azure Emulator
170 | ecf/
171 | rcf/
172 |
173 | # Windows Store app package directories and files
174 | AppPackages/
175 | BundleArtifacts/
176 | Package.StoreAssociation.xml
177 | _pkginfo.txt
178 |
179 | # Visual Studio cache files
180 | # files ending in .cache can be ignored
181 | *.[Cc]ache
182 | # but keep track of directories ending in .cache
183 | !*.[Cc]ache/
184 |
185 | # Others
186 | ClientBin/
187 | ~$*
188 | *~
189 | *.dbmdl
190 | *.dbproj.schemaview
191 | *.pfx
192 | *.publishsettings
193 | node_modules/
194 | orleans.codegen.cs
195 |
196 | # Since there are multiple workflows, uncomment next line to ignore bower_components
197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
198 | #bower_components/
199 |
200 | # RIA/Silverlight projects
201 | Generated_Code/
202 |
203 | # Backup & report files from converting an old project file
204 | # to a newer Visual Studio version. Backup files are not needed,
205 | # because we have git ;-)
206 | _UpgradeReport_Files/
207 | Backup*/
208 | UpgradeLog*.XML
209 | UpgradeLog*.htm
210 |
211 | # SQL Server files
212 | *.mdf
213 | *.ldf
214 |
215 | # Business Intelligence projects
216 | *.rdl.data
217 | *.bim.layout
218 | *.bim_*.settings
219 |
220 | # Microsoft Fakes
221 | FakesAssemblies/
222 |
223 | # GhostDoc plugin setting file
224 | *.GhostDoc.xml
225 |
226 | # Node.js Tools for Visual Studio
227 | .ntvs_analysis.dat
228 |
229 | # Visual Studio 6 build log
230 | *.plg
231 |
232 | # Visual Studio 6 workspace options file
233 | *.opt
234 |
235 | # Visual Studio LightSwitch build output
236 | **/*.HTMLClient/GeneratedArtifacts
237 | **/*.DesktopClient/GeneratedArtifacts
238 | **/*.DesktopClient/ModelManifest.xml
239 | **/*.Server/GeneratedArtifacts
240 | **/*.Server/ModelManifest.xml
241 | _Pvt_Extensions
242 |
243 | # Paket dependency manager
244 | .paket/paket.exe
245 | paket-files/
246 |
247 | # FAKE - F# Make
248 | .fake/
249 |
250 | # JetBrains Rider
251 | .idea/
252 | *.sln.iml
253 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp.WPF/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/src/WeatherApp/WeatherApp/Controls/HorizontalList/HorizontalList.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Windows.Input;
5 | using Xamarin.Forms;
6 |
7 | namespace WeatherApp.Controls
8 | {
9 | public class HorizontalList : Grid
10 | {
11 | private ICommand _innerSelectedCommand;
12 | private readonly ScrollView _scrollView;
13 | private readonly StackLayout _itemsStackLayout;
14 |
15 | public event EventHandler SelectedItemChanged;
16 |
17 | public StackOrientation ListOrientation { get; set; }
18 |
19 | public double Spacing { get; set; }
20 |
21 | public static readonly BindableProperty SelectedCommandProperty =
22 | BindableProperty.Create("SelectedCommand", typeof(ICommand), typeof(HorizontalList), null);
23 |
24 | public static readonly BindableProperty ItemsSourceProperty =
25 | BindableProperty.Create("ItemsSource", typeof(IEnumerable), typeof(HorizontalList), default(IEnumerable