From 4ff5fc95e30afe2fc245626a81dc52f3ef8e5edf Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 6 Jun 2020 02:47:48 +0200 Subject: [PATCH 1/5] Added BitmapIconSourceExtension type --- .../Markup/BitmapIconSourceExtension.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconSourceExtension.cs diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconSourceExtension.cs new file mode 100644 index 00000000000..a506ddd93d0 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconSourceExtension.cs @@ -0,0 +1,37 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Markup; + +namespace Microsoft.Toolkit.Uwp.UI.Extensions +{ + /// + /// Custom which can provide values. + /// + [MarkupExtensionReturnType(ReturnType = typeof(BitmapIconSource))] + public sealed class BitmapIconSourceExtension : MarkupExtension + { + /// + /// Gets or sets the representing the image to display. + /// + public Uri Source { get; set; } + + /// + /// Gets or sets a value indicating whether to display the icon as monochrome. + /// + public bool ShowAsMonochrome { get; set; } + + /// + protected override object ProvideValue() + { + return new BitmapIconSource + { + ShowAsMonochrome = ShowAsMonochrome, + UriSource = Source + }; + } + } +} From ff85e5408f63bfe7dbcc2636da332e46753d32d4 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 6 Jun 2020 02:52:10 +0200 Subject: [PATCH 2/5] Added BitmapIconSource sample --- .../IconExtensions/IconExtensionsPage.xaml | 1 + .../IconExtensions/IconExtensionsXaml.bind | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml index 2655dda17d8..49496b45e9d 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml @@ -18,6 +18,7 @@ + diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind index 48507ef0c43..77b59683e6d 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind @@ -49,6 +49,24 @@ HorizontalAlignment="Center" VerticalAlignment="Center"/> + + + + + + + + + + + + From 0a77566c3de31ab7c01d1eca1b4f38a6e6295044 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 6 Jun 2020 02:57:15 +0200 Subject: [PATCH 3/5] Aligned APIs to original UWP ones, fixed docs --- .../IconExtensions/IconExtensionsPage.xaml | 4 ++-- .../IconExtensions/IconExtensionsXaml.bind | 10 +++++----- .../Markup/Abstract/TextIconExtension{T}.cs | 20 ------------------- .../Extensions/Markup/FontIconExtension.cs | 7 ++++++- .../Markup/FontIconSourceExtension.cs | 7 ++++++- .../Extensions/Markup/SymbolIconExtension.cs | 9 +++++++-- .../Markup/SymbolIconSourceExtension.cs | 9 +++++++-- 7 files changed, 33 insertions(+), 33 deletions(-) delete mode 100644 Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension{T}.cs diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml index 49496b45e9d..8fc1cc881e5 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml @@ -10,14 +10,14 @@ - + - + diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind index 77b59683e6d..b43e7139b03 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind @@ -26,9 +26,9 @@ Style="{StaticResource BodyTextBlockStyle}"/> - - - + + + - - + + - /// An abstract which to produce text-based icons. - /// - /// The type representing the glyph for the current icon. - public abstract class TextIconExtension : TextIconExtension - { - /// - /// Gets or sets the value representing the icon to display. - /// - public T Glyph { get; set; } - } -} diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs index 1e1c800d442..553a8a282c1 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs @@ -12,8 +12,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions /// Custom which can provide values. /// [MarkupExtensionReturnType(ReturnType = typeof(FontIcon))] - public class FontIconExtension : TextIconExtension + public class FontIconExtension : TextIconExtension { + /// + /// Gets or sets the value representing the icon to display. + /// + public string Glyph { get; set; } + /// /// Gets or sets the font family to use to display the icon. If , "Segoe MDL2 Assets" will be used. /// diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs index af2fe602587..7d2c961f4be 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs @@ -12,8 +12,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions /// Custom which can provide values. /// [MarkupExtensionReturnType(ReturnType = typeof(FontIconSource))] - public class FontIconSourceExtension : TextIconExtension + public class FontIconSourceExtension : TextIconExtension { + /// + /// Gets or sets the value representing the icon to display. + /// + public string Glyph { get; set; } + /// /// Gets or sets the font family to use to display the icon. If , "Segoe MDL2 Assets" will be used. /// diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs index 414a33247c6..a0faebb1557 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs @@ -11,14 +11,19 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions /// Custom which can provide symbol-baased values. /// [MarkupExtensionReturnType(ReturnType = typeof(FontIcon))] - public class SymbolIconExtension : TextIconExtension + public class SymbolIconExtension : TextIconExtension { + /// + /// Gets or sets the value representing the icon to display. + /// + public Symbol Symbol { get; set; } + /// protected override object ProvideValue() { var fontIcon = new FontIcon { - Glyph = unchecked((char)Glyph).ToString(), + Glyph = unchecked((char)Symbol).ToString(), FontFamily = SegoeMDL2AssetsFontFamily, FontWeight = FontWeight, FontStyle = FontStyle, diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs index f5b4e1725da..aaff4958c2a 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs @@ -11,14 +11,19 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions /// Custom which can provide symbol-baased values. /// [MarkupExtensionReturnType(ReturnType = typeof(FontIconSource))] - public class SymbolIconSourceExtension : TextIconExtension + public class SymbolIconSourceExtension : TextIconExtension { + /// + /// Gets or sets the value representing the icon to display. + /// + public Symbol Symbol { get; set; } + /// protected override object ProvideValue() { var fontIcon = new FontIconSource { - Glyph = unchecked((char)Glyph).ToString(), + Glyph = unchecked((char)Symbol).ToString(), FontFamily = SegoeMDL2AssetsFontFamily, FontWeight = FontWeight, FontStyle = FontStyle, From 02dab4876148c490c2918ca63a8b4d7e2813b122 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 6 Jun 2020 03:23:23 +0200 Subject: [PATCH 4/5] Fixed UWP unit test project build --- UnitTests/UnitTests.UWP/UnitTestApp.xaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitTests/UnitTests.UWP/UnitTestApp.xaml b/UnitTests/UnitTests.UWP/UnitTestApp.xaml index f9e9631c047..b2da08dfa99 100644 --- a/UnitTests/UnitTests.UWP/UnitTestApp.xaml +++ b/UnitTests/UnitTests.UWP/UnitTestApp.xaml @@ -9,7 +9,7 @@ - + + IconSource="{extensions:SymbolIconSource Symbol=Play}"/>