-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
402 additions
and
27 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
|
||
namespace pg.DarkSky.Wpf.Helpers | ||
{ | ||
/// <summary> | ||
/// Segít az ikonok megjelenítésében, hogy ne kelljen DependencyProperty-t implementálni | ||
/// | ||
/// Loptam: https://www.codeproject.com/Articles/71348/Binding-on-a-Property-which-is-not-a-DependencyPro | ||
/// </summary> | ||
public class ExtendedBinding : FrameworkElement | ||
{ | ||
#region Source DP | ||
//We don't know what will be the Source/target type so we keep 'object'. | ||
public static readonly DependencyProperty SourceProperty = | ||
DependencyProperty.Register("Source", typeof(object), typeof(ExtendedBinding), | ||
new FrameworkPropertyMetadata() | ||
{ | ||
BindsTwoWayByDefault = true, | ||
DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, | ||
}); | ||
public Object Source | ||
{ | ||
get { return GetValue(ExtendedBinding.SourceProperty); } | ||
set { SetValue(ExtendedBinding.SourceProperty, value); } | ||
} | ||
#endregion | ||
|
||
#region Target DP | ||
//We don't know what will be the Source/target type so we keep 'object'. | ||
public static readonly DependencyProperty TargetProperty = | ||
DependencyProperty.Register("Target", typeof(object), typeof(ExtendedBinding), | ||
new FrameworkPropertyMetadata() | ||
{ | ||
BindsTwoWayByDefault = true, | ||
DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, | ||
}); | ||
public Object Target | ||
{ | ||
get { return GetValue(ExtendedBinding.TargetProperty); } | ||
set { SetValue(ExtendedBinding.TargetProperty, value); } | ||
} | ||
#endregion | ||
|
||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) | ||
{ | ||
base.OnPropertyChanged(e); | ||
if (e.Property.Name == ExtendedBinding.SourceProperty.Name) | ||
{ | ||
//no loop wanted | ||
if (!object.ReferenceEquals(Source, Target)) | ||
Target = Source; | ||
} | ||
else if (e.Property.Name == ExtendedBinding.TargetProperty.Name) | ||
{ | ||
//no loop wanted | ||
if (!object.ReferenceEquals(Source, Target)) | ||
Source = Target; | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using MahApps.Metro.IconPacks; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace pg.DarkSky.Wpf.Helpers | ||
{ | ||
public static class IconHelpers | ||
{ | ||
/// <summary> | ||
/// A SkyCons icon azonosítókat átforgatjuk mahapps.Icon.wehater azonosítókká | ||
/// </summary> | ||
/// <param name="icon"></param> | ||
/// <returns></returns> | ||
public static PackIconWeatherIconsKind IconToWeatherIcon(this string icon) | ||
{ | ||
switch (icon) | ||
{ | ||
case "clear-day": | ||
return PackIconWeatherIconsKind.DaySunny; | ||
case "clear-night": | ||
return PackIconWeatherIconsKind.NightClear; | ||
case "partly-cloudy-day": | ||
return PackIconWeatherIconsKind.DayCloudy; | ||
case "partly-cloudy-night": | ||
return PackIconWeatherIconsKind.NightCloudy; | ||
case "cloudy": | ||
return PackIconWeatherIconsKind.Cloudy; | ||
case "rain": | ||
return PackIconWeatherIconsKind.Rain; | ||
case "sleet": | ||
return PackIconWeatherIconsKind.Sleet; | ||
case "snow": | ||
return PackIconWeatherIconsKind.Snow; | ||
case "wind": | ||
return PackIconWeatherIconsKind.StrongWind; | ||
case "fog": | ||
return PackIconWeatherIconsKind.Fog; | ||
default: | ||
return PackIconWeatherIconsKind.Na; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Átalakítja a szélsebességet, ami m/s-ban jön (SI) Beaufort skálává | ||
/// https://hu.wikipedia.org/wiki/Beaufort-sk%C3%A1la | ||
/// | ||
/// todo: a wikipédia alapján a szél jellemzőit meg lehetne tooltip-ben jeleníteni | ||
/// </summary> | ||
/// <param name="windspeed"></param> | ||
/// <returns></returns> | ||
public static PackIconWeatherIconsKind WindSpeedToBeaufortIcon(this double windspeed) | ||
{ | ||
if (windspeed <= 0.3d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort0; | ||
} | ||
if (windspeed <= 1.7d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort1; | ||
} | ||
if (windspeed <= 3.1d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort2; | ||
} | ||
if (windspeed <= 5.3d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort3; | ||
} | ||
if (windspeed <= 8.1d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort4; | ||
} | ||
if (windspeed <= 10.9d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort5; | ||
} | ||
if (windspeed <= 13.3d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort6; | ||
} | ||
if (windspeed <= 16.9d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort7; | ||
} | ||
if (windspeed <= 20.0d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort8; | ||
} | ||
if (windspeed <= 23.7d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort9; | ||
} | ||
if (windspeed <= 27.9d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort10; | ||
} | ||
if (windspeed <= 31.9d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort11; | ||
} | ||
if (windspeed <= 33.3d) | ||
{ | ||
return PackIconWeatherIconsKind.WindBeaufort12; | ||
} | ||
|
||
//ha kifutottunk a skálából, jelezzük az érvénytelen értéket | ||
return PackIconWeatherIconsKind.Na; | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.