diff --git a/MyFirstMauiApp/WeatherClient/MainPage.xaml b/MyFirstMauiApp/WeatherClient/MainPage.xaml index 1c07dca..0d5644b 100644 --- a/MyFirstMauiApp/WeatherClient/MainPage.xaml +++ b/MyFirstMauiApp/WeatherClient/MainPage.xaml @@ -2,7 +2,12 @@ + + + + @@ -20,15 +25,15 @@ diff --git a/MyFirstMauiApp/WeatherClient/MainPage.xaml.cs b/MyFirstMauiApp/WeatherClient/MainPage.xaml.cs index 7466e9b..a31bb94 100644 --- a/MyFirstMauiApp/WeatherClient/MainPage.xaml.cs +++ b/MyFirstMauiApp/WeatherClient/MainPage.xaml.cs @@ -1,8 +1,11 @@ -namespace WeatherClient +using WeatherClient.Models; +using WeatherClient.ViewModels; + +namespace WeatherClient { public partial class MainPage : ContentPage { - int count = 0; + private WeatherViewModel _context; public MainPage() { @@ -14,7 +17,9 @@ btnRefresh.IsEnabled = false; actIsBusy.IsRunning = true; - BindingContext = await Services.WeatherServer.GetWeather(txtPostalCode.Text); + WeatherData weatherData = await Services.WeatherServer.GetWeather(txtPostalCode.Text); + _context = new WeatherViewModel() { WeatherData = weatherData }; + BindingContext = _context; btnRefresh.IsEnabled = true; actIsBusy.IsRunning = false; diff --git a/MyFirstMauiApp/WeatherClient/ViewModels/WeatherViewModel.cs b/MyFirstMauiApp/WeatherClient/ViewModels/WeatherViewModel.cs new file mode 100644 index 0000000..4191b6a --- /dev/null +++ b/MyFirstMauiApp/WeatherClient/ViewModels/WeatherViewModel.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WeatherClient.Models; + +namespace WeatherClient.ViewModels +{ + public class WeatherViewModel : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + + private WeatherData _weatherData; + public WeatherData WeatherData + { + get { return _weatherData; } + set + { + _weatherData = value; + OnPropertyChanged(nameof(WeatherData)); + } + } + + + private void OnPropertyChanged(string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +}