diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj index 5c1368815..3b16d0f56 100644 --- a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj +++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj @@ -40,6 +40,7 @@ + diff --git a/src/Artemis.UI.Shared/Controls/ArtemisIcon.xaml b/src/Artemis.UI.Shared/Controls/ArtemisIcon.xaml new file mode 100644 index 000000000..673f285c3 --- /dev/null +++ b/src/Artemis.UI.Shared/Controls/ArtemisIcon.xaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/Artemis.UI.Shared/Controls/ArtemisIcon.xaml.cs b/src/Artemis.UI.Shared/Controls/ArtemisIcon.xaml.cs new file mode 100644 index 000000000..7a149e8f9 --- /dev/null +++ b/src/Artemis.UI.Shared/Controls/ArtemisIcon.xaml.cs @@ -0,0 +1,88 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using MaterialDesignThemes.Wpf; + +namespace Artemis.UI.Shared.Controls +{ + /// + /// Interaction logic for ArtemisIcon.xaml + /// + public partial class ArtemisIcon : UserControl + { + public static readonly DependencyProperty IconProperty = DependencyProperty.Register(nameof(Icon), typeof(object), typeof(ArtemisIcon), + new FrameworkPropertyMetadata(IconPropertyChangedCallback)); + + public static readonly DependencyProperty PackIconProperty = DependencyProperty.Register(nameof(PackIcon), typeof(PackIconKind?), typeof(ArtemisIcon), + new FrameworkPropertyMetadata(IconPropertyChangedCallback)); + + public static readonly DependencyProperty SvgSourceProperty = DependencyProperty.Register(nameof(SvgSource), typeof(Uri), typeof(ArtemisIcon), + new FrameworkPropertyMetadata(IconPropertyChangedCallback)); + + private bool _inCallback; + + public ArtemisIcon() + { + InitializeComponent(); + } + + /// + /// Gets or sets the currently displayed icon as either a or an pointing + /// to an SVG + /// + public object Icon + { + get => GetValue(IconProperty); + set => SetValue(IconProperty, value); + } + + /// + /// Gets or sets the + /// + public PackIconKind? PackIcon + { + get => (PackIconKind?) GetValue(PackIconProperty); + set => SetValue(PackIconProperty, value); + } + + /// + /// Gets or sets the pointing to the SVG + /// + public Uri SvgSource + { + get => (Uri) GetValue(SvgSourceProperty); + set => SetValue(SvgSourceProperty, value); + } + + private static void IconPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ArtemisIcon artemisIcon = (ArtemisIcon) d; + if (artemisIcon._inCallback) + return; + + try + { + artemisIcon._inCallback = true; + if (artemisIcon.PackIcon != null) + { + artemisIcon.Icon = artemisIcon.PackIcon; + } + else if (artemisIcon.SvgSource != null) + { + artemisIcon.Icon = artemisIcon.SvgSource; + } + else if (artemisIcon.Icon is string iconString) + { + if (Uri.TryCreate(iconString, UriKind.Absolute, out Uri uriResult)) + artemisIcon.Icon = uriResult; + else if (Enum.TryParse(typeof(PackIconKind), iconString, true, out object result)) + artemisIcon.Icon = result; + } + } + finally + { + artemisIcon._inCallback = false; + } + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index af41888e6..22186756d 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -88,6 +88,7 @@ + @@ -304,6 +305,7 @@ + diff --git a/src/Artemis.UI/Screens/Home/HomeView.xaml b/src/Artemis.UI/Screens/Home/HomeView.xaml index 23ffe9d24..f6e18984f 100644 --- a/src/Artemis.UI/Screens/Home/HomeView.xaml +++ b/src/Artemis.UI/Screens/Home/HomeView.xaml @@ -6,6 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:home="clr-namespace:Artemis.UI.Screens.Home" + xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared" mc:Ignorable="d" d:DesignHeight="574.026" d:DesignWidth="1029.87" @@ -35,7 +36,8 @@ - + + Welcome to Artemis, RGB on steroids.