Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Page.Resources>
- <vm:WeatherVM x:Key="vm" />
- <c:ValuesConverter x:Key="cv" />
- </Page.Resources>
- <RelativePanel DataContext="{StaticResource vm}">
- <TextBox x:Name="currentLocation"
- PlaceholderText="Please wait..."
- IsReadOnly="True"
- Margin="20"
- Width="300"
- Text="{Binding cityData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
- <ListView RelativePanel.Below="currentLocation"
- x:Name="ForecastList"
- Margin="20"
- SelectedItem="{Binding currentDay, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
- ItemsSource="{Binding dailyForecasts}">
- <ListView.ItemTemplate>
- <DataTemplate>
- <StackPanel Margin="10">
- <TextBlock x:Name="dateTB"
- Text="{Binding Date.DayOfWeek}" />
- <TextBlock x:Name="highTB"
- Text="{Binding Temperature.Maximum.Value, Converter={StaticResource cv}}"
- FontSize="10" />
- <TextBlock x:Name="lowTB"
- FontSize="10"
- Text="{Binding Temperature.Minimum.Value, Converter={StaticResource cv}}" />
- </StackPanel>
- </DataTemplate>
- </ListView.ItemTemplate>
- </ListView>
- <ProgressRing x:Name="pRing"
- RelativePanel.Above="ForecastList"
- RelativePanel.AlignHorizontalCenterWith="currentLocation"
- IsActive="{Binding ProgressRingIsActive, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
- Margin="0,0,0,-23" />
- <Image x:Name="Icon"
- Source="{Binding currentDay.Day.IconUrl}"
- Width="50"
- Height="50"
- RelativePanel.AlignVerticalCenterWithPanel="True"
- RelativePanel.AlignHorizontalCenterWithPanel="True"
- RelativePanel.AlignTopWith="ForecastList" />
- <TextBlock x:Name="hight_temp"
- Text="High:"
- FontSize="20"
- RelativePanel.AlignVerticalCenterWithPanel="True"
- RelativePanel.AlignHorizontalCenterWithPanel="True"
- RelativePanel.Below="Icon"
- RelativePanel.AlignLeftWith="Icon" />
- <TextBlock Text="{Binding currentDay.Temperature.Maximum.Value, Converter={StaticResource cv}}"
- x:Name="high"
- FontSize="20"
- RelativePanel.RightOf="hight_temp"
- RelativePanel.Below="Icon" />
- <TextBlock x:Name="low_temp"
- RelativePanel.Below="hight_temp"
- Text="Low: "
- RelativePanel.AlignLeftWith="hight_temp"
- FontSize="20" />
- <TextBlock x:Name="low"
- Text="{Binding currentDay.Temperature.Minimum.Value, Converter={StaticResource cv}}"
- FontSize="20"
- RelativePanel.Below="high"
- RelativePanel.AlignRightWith="high"
- RelativePanel.RightOf="low_temp" />
- <TextBlock x:Name="desc"
- Text="{Binding currentDay.Day.IconPhrase}"
- RelativePanel.Below="low_temp"
- RelativePanel.AlignHorizontalCenterWithPanel="True"
- FontSize="20"
- FontWeight="Bold"
- RelativePanel.AlignLeftWith="low_temp" />
- </RelativePanel>
- </Page>
- public AccuWeather accuWeather { get; set; }
- private string _cityData;
- public string cityData {
- get { return _cityData; }
- set {
- if (value != _cityData) {
- _cityData = value;
- onPropertyChanged("cityData");
- GetWeatherData();
- }
- }
- }
- private DailyForecast _currentDay;
- public DailyForecast currentDay {
- get { return _currentDay; }
- set {
- if (value != _currentDay) {
- _currentDay = value;
- onPropertyChanged("currentDay");
- }
- }
- }
- private bool _ring;
- public bool ring {
- get { return _ring; }
- set {
- if (value != _ring) {
- _ring = value;
- onPropertyChanged("ring");
- }
- }
- }
- public ObservableCollection<DailyForecast> dailyForecasts { get; set; }
- public WeatherVM() {
- GetCuurentLocation();
- dailyForecasts = new ObservableCollection<DailyForecast>();
- ring = true;
- }
- private async void GetCuurentLocation() {
- cityData = await BingLocator.GetCityData();
- }
- public async void GetWeatherData() {
- var geoposition = await LocationManager.GetGeopositionAsync();
- var currentLocationKey = await WeatherAPI.GetCityDstaAsync(geoposition.Coordinate.Point.Position.Latitude, geoposition.Coordinate.Point.Position.Longitude);
- var weatherData = await WeatherAPI.GetWeatherAsync(currentLocationKey.Key);
- if (weatherData != null) {
- foreach (var item in weatherData.DailyForecasts) {
- dailyForecasts.Add(item);
- }
- }
- ring = false;
- currentDay = dailyForecasts[0];
- }
- public event PropertyChangedEventHandler PropertyChanged;
- private void onPropertyChanged(string property) {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement