Skip to content

Instantly share code, notes, and snippets.

@lostmsu
Created August 24, 2022 17:36
Show Gist options
  • Save lostmsu/96ffc76f3f7b27d438fc707863d0ef87 to your computer and use it in GitHub Desktop.
Save lostmsu/96ffc76f3f7b27d438fc707863d0ef87 to your computer and use it in GitHub Desktop.
Weather widget for Stack 3.0+
<!--
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&amp;lon=YOUR_LON&amp;units=metric&amp;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>
@lostmsu
Copy link
Author

lostmsu commented Aug 24, 2022

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.

@lostmsu
Copy link
Author

lostmsu commented Sep 16, 2022

Looks like this:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment