Skip to content

Commit

Permalink
[refactor] 将历史天气控件化
Browse files Browse the repository at this point in the history
  • Loading branch information
zxbmmmmmmmmm committed Jun 16, 2024
1 parent f7d016b commit 4892757
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 222 deletions.
226 changes: 226 additions & 0 deletions FluentWeather.Uwp/Controls/HistoricalWeatherGauge.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
<UserControl
x:Class="FluentWeather.Uwp.Controls.HistoricalWeatherGauge"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters1="using:FluentWeather.Uwp.Shared.Helpers.ValueConverters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dv="using:Telerik.UI.Xaml.Controls.DataVisualization"
xmlns:local="using:FluentWeather.Uwp.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">

<Grid>
<dv:RadLinearGauge
Height="120"
Margin="24,0"
x:DefaultBindMode="OneWay"
LabelStep="1"
MaxValue="{x:Bind HistoricalDailyWeather.HistoricalMaxTemperature}"
MinValue="{x:Bind HistoricalDailyWeather.HistoricalMinTemperature}"
TickStep="1">
<dv:RadLinearGauge.TickTemplate>
<DataTemplate />
</dv:RadLinearGauge.TickTemplate>
<dv:RadLinearGauge.LabelTemplate>
<DataTemplate />
</dv:RadLinearGauge.LabelTemplate>
<!-- 历史最高/最低温 指示条 -->
<dv:SegmentedLinearGaugeIndicator Value="{x:Bind HistoricalDailyWeather.HistoricalMaxTemperature}">
<dv:BarIndicatorSegment
Length="{x:Bind converters1:ConverterMethods.Subtract(HistoricalDailyWeather.AverageMinTemperature, HistoricalDailyWeather.HistoricalMinTemperature)}"
Stroke="{ThemeResource HistoricalWeatherBaseRangeStroke}"
Thickness="4" />
<dv:BarIndicatorSegment
Length="{x:Bind converters1:ConverterMethods.Subtract(HistoricalDailyWeather.AverageMaxTemperature, HistoricalDailyWeather.AverageMinTemperature)}"
Stroke="{ThemeResource HistoricalWeatherAverageRangeStroke}"
Thickness="4" />
<dv:BarIndicatorSegment
Length="{x:Bind converters1:ConverterMethods.Subtract(HistoricalDailyWeather.HistoricalMaxTemperature, HistoricalDailyWeather.AverageMaxTemperature)}"
Stroke="{ThemeResource HistoricalWeatherBaseRangeStroke}"
Thickness="4" />
</dv:SegmentedLinearGaugeIndicator>
<!-- 平均低温 -->
<dv:MarkerGaugeIndicator Margin="0,-40,0,0" Value="{x:Bind HistoricalDailyWeather.AverageMinTemperature}">
<dv:MarkerGaugeIndicator.Content>
<StackPanel>
<TextBlock
x:Uid="AverageLowTemp"
FontSize="12"
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
<TextBlock
Margin="4,0,0,0"
HorizontalAlignment="Center"
FontSize="18">
<Run Text="{x:Bind HistoricalDailyWeather.AverageMinTemperature}" /><Run Text="°" />
</TextBlock>
<Ellipse
Width="8"
Height="8"
HorizontalAlignment="Center"
Fill="{ThemeResource HistoricalWeatherAveragePointFill}" />
</StackPanel>
</dv:MarkerGaugeIndicator.Content>
</dv:MarkerGaugeIndicator>

<!-- 平均高温 -->
<dv:MarkerGaugeIndicator Margin="0,-40,0,0" Value="{x:Bind HistoricalDailyWeather.AverageMaxTemperature}">
<dv:MarkerGaugeIndicator.Content>
<StackPanel>
<TextBlock
x:Uid="AverageHighTemp"
FontSize="12"
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
<TextBlock
Margin="4,0,0,0"
HorizontalAlignment="Center"
FontSize="18">
<Run Text="{x:Bind HistoricalDailyWeather.AverageMaxTemperature}" /><Run Text="°" />

</TextBlock>
<Ellipse
Width="8"
Height="8"
HorizontalAlignment="Center"
Fill="{ThemeResource HistoricalWeatherAveragePointFill}" />
</StackPanel>
</dv:MarkerGaugeIndicator.Content>
</dv:MarkerGaugeIndicator>

<!-- 历史低温 -->
<dv:MarkerGaugeIndicator Margin="0,-56,0,0" Value="{x:Bind HistoricalDailyWeather.HistoricalMinTemperature}">
<dv:MarkerGaugeIndicator.Content>
<StackPanel>
<TextBlock
HorizontalAlignment="Center"
FontSize="12"
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
TextAlignment="Center"
TextWrapping="WrapWholeWords">
<Run FontSize="12" Text="{x:Bind HistoricalDailyWeather.HistoricalMinTemperatureDate.Year}" />
<LineBreak />
<Run x:Uid="HistoricalLowTemp" />
</TextBlock>
<TextBlock
Margin="4,0,0,0"
HorizontalAlignment="Center"
FontSize="18">
<Run Text="{x:Bind HistoricalDailyWeather.HistoricalMinTemperature}" /><Run Text="°" />
</TextBlock>
<Ellipse
Width="8"
Height="8"
HorizontalAlignment="Center"
Fill="{ThemeResource HistoricalWeatherHighestLowestPointFill}" />
</StackPanel>
</dv:MarkerGaugeIndicator.Content>
</dv:MarkerGaugeIndicator>

<!-- 历史高温 -->
<dv:MarkerGaugeIndicator Margin="0,-56,0,0" Value="{x:Bind HistoricalDailyWeather.HistoricalMaxTemperature}">
<dv:MarkerGaugeIndicator.Content>
<StackPanel>
<TextBlock
HorizontalAlignment="Center"
FontSize="12"
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}"
TextAlignment="Center">
<Run FontSize="12" Text="{x:Bind HistoricalDailyWeather.HistoricalMaxTemperatureDate.Year}" />
<LineBreak />
<Run x:Uid="HistoricalHighTemp" />
</TextBlock>
<TextBlock
Margin="4,0,0,0"
HorizontalAlignment="Center"
FontSize="18">
<Run Text="{x:Bind HistoricalDailyWeather.HistoricalMaxTemperature}" /><Run Text="°" />
</TextBlock>
<Ellipse
Width="8"
Height="8"
HorizontalAlignment="Center"
Fill="{ThemeResource HistoricalWeatherHighestLowestPointFill}" />
</StackPanel>
</dv:MarkerGaugeIndicator.Content>
</dv:MarkerGaugeIndicator>



<!-- 今日天气 指示条 -->
<dv:SegmentedLinearGaugeIndicator dv:RadLinearGauge.IndicatorOffset="12" Value="{x:Bind HistoricalDailyWeather.HistoricalMaxTemperature}">
<dv:BarIndicatorSegment
Length="{x:Bind converters1:ConverterMethods.Subtract(WeatherToday.MinTemperature, HistoricalDailyWeather.HistoricalMinTemperature)}"
Stroke="Transparent"
Thickness="4" />

<dv:BarIndicatorSegment
Length="{x:Bind converters1:ConverterMethods.Subtract(WeatherToday.MaxTemperature, WeatherToday.MinTemperature)}"
Stroke="{ThemeResource HistoricalWeatherTodayRangeStroke}"
Thickness="4" />
<dv:BarIndicatorSegment
Length="{x:Bind converters1:ConverterMethods.Subtract(HistoricalDailyWeather.HistoricalMaxTemperature, WeatherToday.MaxTemperature)}"
Stroke="Transparent"
Thickness="4" />
</dv:SegmentedLinearGaugeIndicator>

<!-- 今日低温 -->
<dv:MarkerGaugeIndicator
x:Name="LowestTempTodayIndicator"
dv:RadLinearGauge.IndicatorOffset="32"
Value="{x:Bind WeatherToday.MinTemperature}">
<dv:MarkerGaugeIndicator.Content>
<StackPanel VerticalAlignment="Bottom">
<Ellipse
Width="8"
Height="8"
HorizontalAlignment="Center"
Fill="{ThemeResource HistoricalWeatherTodayPointFill}" />
<TextBlock
Margin="2,0,0,0"
HorizontalAlignment="Center"
FontSize="18">
<Run Text="{x:Bind LowestTempTodayIndicator.Value}" /><Run Text="°" />

</TextBlock>
<TextBlock
x:Uid="TodayLowTemp"
FontSize="12"
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
</StackPanel>
</dv:MarkerGaugeIndicator.Content>
</dv:MarkerGaugeIndicator>

<!-- 今日高温 -->
<dv:MarkerGaugeIndicator
x:Name="HighestTempTodayIndicator"
dv:RadLinearGauge.IndicatorOffset="32"
Value="{x:Bind WeatherToday.MaxTemperature}">
<dv:MarkerGaugeIndicator.Content>
<StackPanel VerticalAlignment="Bottom">
<Ellipse
Width="8"
Height="8"
HorizontalAlignment="Center"
Fill="{ThemeResource HistoricalWeatherTodayPointFill}" />
<TextBlock
Margin="2,0,0,0"
HorizontalAlignment="Center"
FontSize="18">
<Run Text="{x:Bind HighestTempTodayIndicator.Value}" /><Run Text="°" />
</TextBlock>
<TextBlock
x:Uid="TodayHighTemp"
FontSize="12"
Foreground="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
</StackPanel>
</dv:MarkerGaugeIndicator.Content>
</dv:MarkerGaugeIndicator>




</dv:RadLinearGauge>

</Grid>
</UserControl>
50 changes: 50 additions & 0 deletions FluentWeather.Uwp/Controls/HistoricalWeatherGauge.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using FluentWeather.Abstraction.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

//https://go.microsoft.com/fwlink/?LinkId=234236 上介绍了“用户控件”项模板

namespace FluentWeather.Uwp.Controls
{
public sealed partial class HistoricalWeatherGauge : UserControl
{
public HistoricalWeatherGauge()
{
this.InitializeComponent();
}

public HistoricalDailyWeatherBase HistoricalDailyWeather
{
get => (HistoricalDailyWeatherBase)GetValue(HistoricalDailyWeatherProperty);
set => SetValue(HistoricalDailyWeatherProperty, value);
}

public static readonly DependencyProperty HistoricalDailyWeatherProperty =
DependencyProperty.Register(nameof(HistoricalDailyWeather), typeof(HistoricalDailyWeatherBase), typeof(HistoricalWeatherGauge), new PropertyMetadata(default));



public WeatherDailyBase WeatherToday
{
get => (WeatherDailyBase)GetValue(WeatherTodayProperty);
set => SetValue(WeatherTodayProperty, value);
}

public static readonly DependencyProperty WeatherTodayProperty =
DependencyProperty.Register(nameof(WeatherToday), typeof(WeatherDailyBase), typeof(HistoricalWeatherGauge), new PropertyMetadata(default));


}
}
7 changes: 7 additions & 0 deletions FluentWeather.Uwp/FluentWeather.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
<Compile Include="Controls\Dialogs\UpdateDialog.xaml.cs">
<DependentUpon>UpdateDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\HistoricalWeatherGauge.xaml.cs">
<DependentUpon>HistoricalWeatherGauge.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\HourlyDataChart.xaml.cs">
<DependentUpon>HourlyDataChart.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -489,6 +492,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\HistoricalWeatherGauge.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\HourlyDataChart.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Loading

0 comments on commit 4892757

Please sign in to comment.