Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Donghuan-He/MainPage.xaml.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (42 sloc)
1.24 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace WeatherApp; | |
public partial class MainPage : ContentPage | |
{ | |
RestService _restService; | |
public MainPage() | |
{ | |
InitializeComponent(); | |
_restService = new RestService(); | |
BindingContext = new WeatherData(); | |
} | |
async void OnGetWeatherButtonClicked(object sender,EventArgs e) { | |
if (!string.IsNullOrWhiteSpace(_cityEntry.Text)) | |
{ | |
var _BindingContext = BindingContext as WeatherData; | |
if (!_BindingContext.IsEnabled) | |
{ | |
DisplayAlert("", "Please Wait", "close"); | |
return; | |
} | |
_BindingContext.IsEnabled = false; | |
WeatherData weatherData = await | |
_restService. | |
GetWeatherData(GenerateRequestURL(Api.Endpoint)); | |
weatherData.IsEnabled = true; | |
BindingContext = weatherData; | |
} | |
else | |
{ | |
DisplayAlert("", "Please enter the city","close"); | |
} | |
} | |
string GenerateRequestURL(string endPoint) { | |
string requestUri = endPoint; | |
requestUri += $"?query={_cityEntry.Text}"; | |
requestUri += $"&unit={Api.unit}"; | |
requestUri += $"&version=today"; | |
requestUri += $"&language={Api.Language}"; | |
requestUri += $"&appid={Api.AppId}"; | |
requestUri += $"&appsecret={Api.Appsecret}"; | |
return requestUri; | |
} | |
} | |