Created
August 24, 2022 17:36
-
-
Save lostmsu/96ffc76f3f7b27d438fc707863d0ef87 to your computer and use it in GitHub Desktop.
Weather widget for Stack 3.0+
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
<!-- | |
xmlns:binding="clr-namespace:LostTech.Stack.Widgets.DataBinding;assembly=LostTech.Stack.Widgets" | |
xmlns:dataSources="clr-namespace:LostTech.Stack.Widgets.DataSources;assembly=LostTech.Stack.Widgets" | |
--> | |
<StackPanel Orientation="Horizontal"> | |
<StackPanel.Resources> | |
<dataSources:WebDataSource x:Key="Weather" | |
Url="https://api.openweathermap.org/data/2.5/weather?lat=YOUR_LAT&lon=YOUR_LON&units=metric&appid=PUT_YOUR_OWN_HERE" | |
dataSources:DataSource.RefreshInterval="0:15:0" /> | |
<binding:ConverterPipeline x:Key="WeatherIcon"> | |
<binding:ParametrizedConverter Parameter="weather.[0].icon"> | |
<binding:JsonParser /> | |
</binding:ParametrizedConverter> | |
<binding:ParametrizedConverter Parameter="http://openweathermap.org/img/wn/{0}.png"> | |
<binding:Formatter /> | |
</binding:ParametrizedConverter> | |
</binding:ConverterPipeline> | |
<binding:JsonParser x:Key="JsonParser"/> | |
</StackPanel.Resources> | |
<Image Height="40" Width="40" Margin="0,3" | |
Source="{Binding Content, | |
Source={StaticResource Weather}, | |
Converter={StaticResource WeatherIcon}, | |
Mode=OneWay, | |
IsAsync=True}" | |
/> | |
<TextBlock Foreground="White" Margin="5,3" | |
VerticalAlignment="Center" | |
FontSize="20"> | |
<Run Text="{Binding Content, | |
Source={StaticResource Weather}, | |
Converter={StaticResource JsonParser}, | |
ConverterParameter=main.temp, | |
Mode=OneWay, | |
StringFormat={}{0:0}°C, | |
IsAsync=True}"/> | |
</TextBlock> | |
</StackPanel> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forget to replace
YOUR_*
bits and add xmlns to the beginning of the screen layout.You need Stack 3.0 for this to work. If it is not released yet, ping me here to add you to betas group.