Ooui-tws-port/Samples/WeatherApp/WeatherPage.xaml.cs

36 lines
1.0 KiB
C#
Raw Normal View History

2017-12-12 20:43:38 +00:00
using System;
using Xamarin.Forms;
namespace WeatherApp
{
public partial class WeatherPage : ContentPage
{
public WeatherPage()
{
InitializeComponent();
this.Title = "Sample Weather App";
getWeatherBtn.Clicked += GetWeatherBtn_Clicked;
//Set the default binding to a default object for now
2018-09-02 14:29:53 +00:00
this.BindingContext = Weather;
unitOfMeasure.ItemsSource = Weather.UnitOfMeasures;
2017-12-12 20:43:38 +00:00
}
2018-09-02 14:29:53 +00:00
public Weather Weather { get; } = new Weather();
2017-12-12 20:43:38 +00:00
private async void GetWeatherBtn_Clicked(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(zipCodeEntry.Text))
{
2018-09-02 14:29:53 +00:00
Weather weather = await Core.GetWeather(zipCodeEntry.Text, (string)unitOfMeasure.SelectedItem);
2017-12-12 20:43:38 +00:00
if (weather != null)
{
this.BindingContext = weather;
getWeatherBtn.Text = "Search Again";
}
}
}
}
2018-06-29 15:30:18 +00:00
}