From 30573764b41823239ca6a45a1076f6a4beb8be7e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 25 Jan 2020 14:53:47 +0100 Subject: [PATCH 01/34] Added FontIcon markup extension --- .../Extensions/Markup/FontIcon.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIcon.cs diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIcon.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIcon.cs new file mode 100644 index 00000000000..5d268ea3005 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIcon.cs @@ -0,0 +1,38 @@ +// 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 Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Markup; +using Windows.UI.Xaml.Media; + +namespace Microsoft.Toolkit.Uwp.UI.Extensions +{ + /// + /// Custom which can provide values. + /// + [Bindable] + [MarkupExtensionReturnType(ReturnType = typeof(Windows.UI.Xaml.Controls.FontIcon))] + public class FontIcon : MarkupExtension + { + /// + /// Gets or sets the 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. + /// + public FontFamily FontFamily { get; set; } + + /// + protected override object ProvideValue() + { + return new Windows.UI.Xaml.Controls.FontIcon + { + Glyph = Glyph, + FontFamily = FontFamily ?? new FontFamily("Segoe MDL2 Assets") + }; + } + } +} From 728f1ce284e380bac234904232a9e6d39b3338a9 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 25 Jan 2020 14:53:56 +0100 Subject: [PATCH 02/34] Removed unnecessary using directives --- Microsoft.Toolkit.Uwp.UI/Extensions/Markup/NullableBool.cs | 5 ----- Microsoft.Toolkit.Uwp.UI/Extensions/Markup/OnDevice.cs | 1 - 2 files changed, 6 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/NullableBool.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/NullableBool.cs index cb1831ea4ab..e3a5224dfa8 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/NullableBool.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/NullableBool.cs @@ -2,11 +2,6 @@ // 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 System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Markup; diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/OnDevice.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/OnDevice.cs index 21fdf480344..866a54383a1 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/OnDevice.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/OnDevice.cs @@ -2,7 +2,6 @@ // 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.ApplicationModel; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Markup; From 800efbaa3c335bd168f243f507b1802c12d15b61 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 25 Jan 2020 15:14:40 +0100 Subject: [PATCH 03/34] Renamed the FontIcon markup extension --- .../Markup/{FontIcon.cs => FontIconExtension.cs} | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename Microsoft.Toolkit.Uwp.UI/Extensions/Markup/{FontIcon.cs => FontIconExtension.cs} (81%) diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIcon.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs similarity index 81% rename from Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIcon.cs rename to Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs index 5d268ea3005..efebf1111c1 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIcon.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Markup; using Windows.UI.Xaml.Media; @@ -9,11 +10,11 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions { /// - /// Custom which can provide values. + /// Custom which can provide values. /// [Bindable] - [MarkupExtensionReturnType(ReturnType = typeof(Windows.UI.Xaml.Controls.FontIcon))] - public class FontIcon : MarkupExtension + [MarkupExtensionReturnType(ReturnType = typeof(FontIcon))] + public class FontIconExtension : MarkupExtension { /// /// Gets or sets the representing the icon to display. @@ -28,7 +29,7 @@ public class FontIcon : MarkupExtension /// protected override object ProvideValue() { - return new Windows.UI.Xaml.Controls.FontIcon + return new FontIcon { Glyph = Glyph, FontFamily = FontFamily ?? new FontFamily("Segoe MDL2 Assets") From c2f00be1e2d8b6290fb1faa34c0f5c7fb6738400 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 25 Jan 2020 15:18:44 +0100 Subject: [PATCH 04/34] Added FontIcon tests --- .../Test_FontIconExtensionMarkupExtension.cs | 63 +++++++++++++++++++ UnitTests/UnitTests.csproj | 1 + 2 files changed, 64 insertions(+) create mode 100644 UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs diff --git a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs new file mode 100644 index 00000000000..9b5cad323c1 --- /dev/null +++ b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs @@ -0,0 +1,63 @@ +// 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 Microsoft.Toolkit.Uwp.UI.Extensions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Markup; + +namespace UnitTests.Extensions +{ + [TestClass] + public class Test_FontIconExtensionMarkupExtension + { + [TestCategory("FontIconExtensionMarkupExtension")] + [UITestMethod] + public void Test_FontIconExtension_MarkupExtension_ProvideSegoeMdl2Asset() + { + var treeroot = XamlReader.Load(@" + +") as FrameworkElement; + + var button = treeroot.FindChildByName("Check") as AppBarButton; + + Assert.IsNotNull(button, $"Could not find the {nameof(AppBarButton)} control in tree."); + + var icon = button.Icon as FontIcon; + + Assert.IsNotNull(icon, $"Could not find the {nameof(FontIcon)} element in button."); + + Assert.AreEqual(icon.Glyph, "\uE105", "Expected icon glyph to be E105."); + Assert.AreEqual(icon.FontFamily.Source, "Segoe MDL2 Assets", "Expected font family to be Segoe MDL2 Assets"); + } + + [TestCategory("FontIconExtensionMarkupExtension")] + [UITestMethod] + public void Test_FontIconExtension_MarkupExtension_ProvideSegoeUI() + { + var treeroot = XamlReader.Load(@" + +") as FrameworkElement; + + var button = treeroot.FindChildByName("Check") as AppBarButton; + + Assert.IsNotNull(button, $"Could not find the {nameof(AppBarButton)} control in tree."); + + var icon = button.Icon as FontIcon; + + Assert.IsNotNull(icon, $"Could not find the {nameof(FontIcon)} element in button."); + + Assert.AreEqual(icon.Glyph, "\uE105", "Expected icon glyph to be E105."); + Assert.AreEqual(icon.FontFamily.Source, "Segoe MDL2 Assets", "Expected font family to be Segoe UI"); + } + } +} diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index 1813e7836db..6b7e93bb5eb 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -134,6 +134,7 @@ + From 4493ffc41e9f0c8887345e8156aef4d7d5e48bc4 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 26 Jan 2020 17:22:11 +0100 Subject: [PATCH 05/34] Fixed a typo in the test XAML --- UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs index 9b5cad323c1..dcfe43f8cda 100644 --- a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs +++ b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs @@ -22,7 +22,7 @@ public void Test_FontIconExtension_MarkupExtension_ProvideSegoeMdl2Asset() xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions""> - + ") as FrameworkElement; var button = treeroot.FindChildByName("Check") as AppBarButton; @@ -45,7 +45,7 @@ public void Test_FontIconExtension_MarkupExtension_ProvideSegoeUI() xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions""> - + ") as FrameworkElement; var button = treeroot.FindChildByName("Check") as AppBarButton; From e8d4309c3d9866131508a8f2bb9ccff5094ee681 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 12 Feb 2020 14:37:21 +0100 Subject: [PATCH 06/34] Update UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs Co-Authored-By: Michael Hawker MSFT (XAML Llama) --- UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs index dcfe43f8cda..d1c68203ef2 100644 --- a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs +++ b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs @@ -22,7 +22,7 @@ public void Test_FontIconExtension_MarkupExtension_ProvideSegoeMdl2Asset() xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions""> - + ") as FrameworkElement; var button = treeroot.FindChildByName("Check") as AppBarButton; From 6638416fbfde577b6af763e3d1b9722786349e0a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 12 Feb 2020 14:38:29 +0100 Subject: [PATCH 07/34] Update UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs Co-Authored-By: Michael Hawker MSFT (XAML Llama) --- UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs index d1c68203ef2..ce00b7cc0e3 100644 --- a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs +++ b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs @@ -56,7 +56,7 @@ public void Test_FontIconExtension_MarkupExtension_ProvideSegoeUI() Assert.IsNotNull(icon, $"Could not find the {nameof(FontIcon)} element in button."); - Assert.AreEqual(icon.Glyph, "\uE105", "Expected icon glyph to be E105."); + Assert.AreEqual(icon.Glyph, "\uE14D", "Expected icon glyph to be E14D."); Assert.AreEqual(icon.FontFamily.Source, "Segoe MDL2 Assets", "Expected font family to be Segoe UI"); } } From 452a276f2d1bde743f858e00c61aa6341887e4c2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 12 Feb 2020 14:39:01 +0100 Subject: [PATCH 08/34] Update UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs Co-Authored-By: Michael Hawker MSFT (XAML Llama) --- UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs index ce00b7cc0e3..8959c64578b 100644 --- a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs +++ b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs @@ -57,7 +57,7 @@ public void Test_FontIconExtension_MarkupExtension_ProvideSegoeUI() Assert.IsNotNull(icon, $"Could not find the {nameof(FontIcon)} element in button."); Assert.AreEqual(icon.Glyph, "\uE14D", "Expected icon glyph to be E14D."); - Assert.AreEqual(icon.FontFamily.Source, "Segoe MDL2 Assets", "Expected font family to be Segoe UI"); + Assert.AreEqual(icon.FontFamily.Source, "Segoe UI", "Expected font family to be Segoe UI"); } } } From 5577118a17a66af3053ae7b1b71bacafb08196dc Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 12 Feb 2020 14:45:41 +0100 Subject: [PATCH 09/34] Added new FontIcon properties --- .../Extensions/Markup/FontIconExtension.cs | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs index efebf1111c1..8394c244fea 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Windows.UI.Text; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Markup; @@ -21,19 +22,55 @@ public class FontIconExtension : MarkupExtension /// public string Glyph { get; set; } + /// + /// Gets or sets the size of the icon to display. + /// + public double FontSize { get; set; } + /// /// Gets or sets the font family to use to display the icon. If , "Segoe MDL2 Assets" will be used. /// public FontFamily FontFamily { get; set; } + /// + /// Gets or sets the thickness of the icon glyph. + /// + public FontWeight FontWeight { get; set; } = FontWeights.Normal; + + /// + /// Gets or sets the font style for the icon glyph. + /// + public FontStyle FontStyle { get; set; } = FontStyle.Normal; + + /// + /// Gets or sets a value indicating whether automatic text enlargement, to reflect the system text size setting, is enabled. + /// + public bool IsTextScaleFactorEnabled { get; set; } + + /// + /// Gets or sets a value indicating whether the icon is mirrored when the flow direction is right to left. + /// + public bool MirroredWhenRightToLeft { get; set; } + /// protected override object ProvideValue() { - return new FontIcon + var fontIcon = new FontIcon { Glyph = Glyph, - FontFamily = FontFamily ?? new FontFamily("Segoe MDL2 Assets") + FontFamily = FontFamily ?? new FontFamily("Segoe MDL2 Assets"), + FontWeight = FontWeight, + FontStyle = FontStyle, + IsTextScaleFactorEnabled = IsTextScaleFactorEnabled, + MirroredWhenRightToLeft = MirroredWhenRightToLeft }; + + if (FontSize > 0) + { + fontIcon.FontSize = FontSize; + } + + return fontIcon; } } } From 870306cc3c960b4977be789669c74e11efc70b68 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 12 Feb 2020 14:50:21 +0100 Subject: [PATCH 10/34] Added more tests for the new properties --- .../Test_FontIconExtensionMarkupExtension.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs index 8959c64578b..57021acb75e 100644 --- a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs +++ b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Windows.UI.Text; using Microsoft.Toolkit.Uwp.UI.Extensions; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer; @@ -59,5 +60,33 @@ public void Test_FontIconExtension_MarkupExtension_ProvideSegoeUI() Assert.AreEqual(icon.Glyph, "\uE14D", "Expected icon glyph to be E14D."); Assert.AreEqual(icon.FontFamily.Source, "Segoe UI", "Expected font family to be Segoe UI"); } + + [TestCategory("FontIconExtensionMarkupExtension")] + [UITestMethod] + public void Test_FontIconExtension_MarkupExtension_ProvideCustomFontIcon() + { + var treeroot = XamlReader.Load(@" + +") as FrameworkElement; + + var button = treeroot.FindChildByName("Check") as AppBarButton; + + Assert.IsNotNull(button, $"Could not find the {nameof(AppBarButton)} control in tree."); + + var icon = button.Icon as FontIcon; + + Assert.IsNotNull(icon, $"Could not find the {nameof(FontIcon)} element in button."); + + Assert.AreEqual(icon.Glyph, "\uE14D", "Expected icon glyph to be E14D."); + Assert.AreEqual(icon.FontSize, 7.0, "Expected font size of 7"); + Assert.AreEqual(icon.FontFamily.Source, "Segoe MDL2 Assets", "Expected font family to be Segoe UI"); + Assert.AreEqual(icon.FontWeight, FontWeights.Bold, "Expected bold font weight"); + Assert.AreEqual(icon.FontStyle, FontStyle.Italic, "Expected italic font style"); + Assert.AreEqual(icon.IsTextScaleFactorEnabled, true, "Expected IsTextScaleFactorEnabled set to true"); + Assert.AreEqual(icon.MirroredWhenRightToLeft, true, "Expected MirroredWhenRightToLeft set to true"); + } } } From c6d602341145e044c21d0196670aef8a9fe1a4db Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 12 Feb 2020 16:04:03 +0100 Subject: [PATCH 11/34] Added FontIconSourceExtension --- .../Markup/FontIconSourceExtension.cs | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs new file mode 100644 index 00000000000..6e909bd1cb2 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs @@ -0,0 +1,76 @@ +// 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 Windows.UI.Text; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Markup; +using Windows.UI.Xaml.Media; + +namespace Microsoft.Toolkit.Uwp.UI.Extensions +{ + /// + /// Custom which can provide values. + /// + [Bindable] + [MarkupExtensionReturnType(ReturnType = typeof(FontIconSource))] + public class FontIconSourceExtension : MarkupExtension + { + /// + /// Gets or sets the representing the icon to display. + /// + public string Glyph { get; set; } + + /// + /// Gets or sets the size of the icon to display. + /// + public double FontSize { get; set; } + + /// + /// Gets or sets the font family to use to display the icon. If , "Segoe MDL2 Assets" will be used. + /// + public FontFamily FontFamily { get; set; } + + /// + /// Gets or sets the thickness of the icon glyph. + /// + public FontWeight FontWeight { get; set; } = FontWeights.Normal; + + /// + /// Gets or sets the font style for the icon glyph. + /// + public FontStyle FontStyle { get; set; } = FontStyle.Normal; + + /// + /// Gets or sets a value indicating whether automatic text enlargement, to reflect the system text size setting, is enabled. + /// + public bool IsTextScaleFactorEnabled { get; set; } + + /// + /// Gets or sets a value indicating whether the icon is mirrored when the flow direction is right to left. + /// + public bool MirroredWhenRightToLeft { get; set; } + + /// + protected override object ProvideValue() + { + var fontIcon = new FontIconSource + { + Glyph = Glyph, + FontFamily = FontFamily ?? new FontFamily("Segoe MDL2 Assets"), + FontWeight = FontWeight, + FontStyle = FontStyle, + IsTextScaleFactorEnabled = IsTextScaleFactorEnabled, + MirroredWhenRightToLeft = MirroredWhenRightToLeft + }; + + if (FontSize > 0) + { + fontIcon.FontSize = FontSize; + } + + return fontIcon; + } + } +} From e90b0eb79815e41dd8e41250641a9d3661dc48f4 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 12 Feb 2020 16:06:26 +0100 Subject: [PATCH 12/34] Added BitmapIconExtension --- .../Extensions/Markup/BitmapIconExtension.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs new file mode 100644 index 00000000000..d1c8c0a554d --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs @@ -0,0 +1,39 @@ +// 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.Data; +using Windows.UI.Xaml.Markup; + +namespace Microsoft.Toolkit.Uwp.UI.Extensions.Markup +{ + /// + /// Custom which can provide values. + /// + [Bindable] + [MarkupExtensionReturnType(ReturnType = typeof(BitmapIcon))] + public sealed class BitmapIconExtension : 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 BitmapIcon + { + ShowAsMonochrome = ShowAsMonochrome, + UriSource = Source + }; + } + } +} From 0d8f53897ab4783eb2265610de9bdbe8f71ea72d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 24 Mar 2020 20:50:49 +0100 Subject: [PATCH 13/34] Added tests for the FontIconSource extension --- ..._FontIconSourceExtensionMarkupExtension.cs | 113 ++++++++++++++++++ UnitTests/UnitTests.csproj | 1 + 2 files changed, 114 insertions(+) create mode 100644 UnitTests/Extensions/Test_FontIconSourceExtensionMarkupExtension.cs diff --git a/UnitTests/Extensions/Test_FontIconSourceExtensionMarkupExtension.cs b/UnitTests/Extensions/Test_FontIconSourceExtensionMarkupExtension.cs new file mode 100644 index 00000000000..1c1c81852a7 --- /dev/null +++ b/UnitTests/Extensions/Test_FontIconSourceExtensionMarkupExtension.cs @@ -0,0 +1,113 @@ +// 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.Diagnostics.CodeAnalysis; +using Windows.UI.Text; +using Microsoft.Toolkit.Uwp.UI.Extensions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Markup; + +namespace UnitTests.Extensions +{ + [TestClass] + public class Test_FontIconSourceExtensionMarkupExtension + { + [TestCategory("FontIconSourceExtensionMarkupExtension")] + [UITestMethod] + public void Test_FontIconSourceExtension_MarkupExtension_ProvideSegoeMdl2Asset() + { + var treeroot = XamlReader.Load(@" + +") as FrameworkElement; + + var button = treeroot.FindChildByName("Check") as MockSwipeItem; + + Assert.IsNotNull(button, $"Could not find the {nameof(MockSwipeItem)} control in tree."); + + var icon = button.IconSource as FontIconSource; + + Assert.IsNotNull(icon, $"Could not find the {nameof(FontIcon)} element in button."); + + Assert.AreEqual(icon.Glyph, "\uE105", "Expected icon glyph to be E105."); + Assert.AreEqual(icon.FontFamily.Source, "Segoe MDL2 Assets", "Expected font family to be Segoe MDL2 Assets"); + } + + [TestCategory("FontIconSourceExtensionMarkupExtension")] + [UITestMethod] + public void Test_FontIconSourceExtension_MarkupExtension_ProvideSegoeUI() + { + var treeroot = XamlReader.Load(@" + +") as FrameworkElement; + + var button = treeroot.FindChildByName("Check") as MockSwipeItem; + + Assert.IsNotNull(button, $"Could not find the {nameof(MockSwipeItem)} control in tree."); + + var icon = button.IconSource as FontIconSource; + + Assert.IsNotNull(icon, $"Could not find the {nameof(FontIcon)} element in button."); + + Assert.AreEqual(icon.Glyph, "\uE14D", "Expected icon glyph to be E14D."); + Assert.AreEqual(icon.FontFamily.Source, "Segoe UI", "Expected font family to be Segoe UI"); + } + + [TestCategory("FontIconSourceExtensionMarkupExtension")] + [UITestMethod] + public void Test_FontIconSourceExtension_MarkupExtension_ProvideCustomFontIcon() + { + var treeroot = XamlReader.Load(@" + +") as FrameworkElement; + + var button = treeroot.FindChildByName("Check") as MockSwipeItem; + + Assert.IsNotNull(button, $"Could not find the {nameof(MockSwipeItem)} control in tree."); + + var icon = button.IconSource as FontIconSource; + + Assert.IsNotNull(icon, $"Could not find the {nameof(FontIcon)} element in button."); + + Assert.AreEqual(icon.Glyph, "\uE14D", "Expected icon glyph to be E14D."); + Assert.AreEqual(icon.FontSize, 7.0, "Expected font size of 7"); + Assert.AreEqual(icon.FontFamily.Source, "Segoe MDL2 Assets", "Expected font family to be Segoe UI"); + Assert.AreEqual(icon.FontWeight, FontWeights.Bold, "Expected bold font weight"); + Assert.AreEqual(icon.FontStyle, FontStyle.Italic, "Expected italic font style"); + Assert.AreEqual(icon.IsTextScaleFactorEnabled, true, "Expected IsTextScaleFactorEnabled set to true"); + Assert.AreEqual(icon.MirroredWhenRightToLeft, true, "Expected MirroredWhenRightToLeft set to true"); + } + } + + [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402", Justification = "Mock control for tests")] + public class MockSwipeItem : Control + { + public IconSource IconSource + { + get => (IconSource)GetValue(IconSourceProperty); + set => SetValue(IconSourceProperty, value); + } + + public static readonly DependencyProperty IconSourceProperty = + DependencyProperty.Register( + nameof(IconSource), + typeof(IconSource), + typeof(MockSwipeItem), + new PropertyMetadata(default(IconSource))); + } +} \ No newline at end of file diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index b4208dc4fef..ec379bfb48b 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -136,6 +136,7 @@ + From 1af9349d0e78e67513cda4988e777798ba5ee2b8 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 24 Mar 2020 21:27:38 +0100 Subject: [PATCH 14/34] Fixed namespace for BitmapIconExtension type --- .../Extensions/Markup/BitmapIconExtension.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs index d1c8c0a554d..68ded4e2cea 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs @@ -7,7 +7,7 @@ using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Markup; -namespace Microsoft.Toolkit.Uwp.UI.Extensions.Markup +namespace Microsoft.Toolkit.Uwp.UI.Extensions { /// /// Custom which can provide values. From bdcfd9ae97a0ef3e8e12543d96835708fe949a57 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 24 Mar 2020 21:29:09 +0100 Subject: [PATCH 15/34] Added tests for BitmapIconExtension type --- ...Test_BitmapIconExtensionMarkupExtension.cs | 85 +++++++++++++++++++ UnitTests/UnitTests.csproj | 1 + 2 files changed, 86 insertions(+) create mode 100644 UnitTests/Extensions/Test_BitmapIconExtensionMarkupExtension.cs diff --git a/UnitTests/Extensions/Test_BitmapIconExtensionMarkupExtension.cs b/UnitTests/Extensions/Test_BitmapIconExtensionMarkupExtension.cs new file mode 100644 index 00000000000..7eba199289f --- /dev/null +++ b/UnitTests/Extensions/Test_BitmapIconExtensionMarkupExtension.cs @@ -0,0 +1,85 @@ +// 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 System.Linq; +using Microsoft.Toolkit.Uwp.UI.Extensions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Markup; + +namespace UnitTests.Extensions +{ + [TestClass] + public class Test_BitmapIconExtensionMarkupExtension + { + [TestCategory("BitmapIconExtensionMarkupExtension")] + [UITestMethod] + public void Test_BitmapIconExtension_MarkupExtension_ProvideImage() + { + var treeroot = XamlReader.Load(@" + +") as FrameworkElement; + + var button = treeroot.FindChildByName("RootButton") as Button; + + Assert.IsNotNull(button, $"Could not find the {nameof(Button)} control in tree."); + + var item = ((MenuFlyout)button.Flyout)?.Items?.FirstOrDefault() as MenuFlyoutItem; + + Assert.IsNotNull(button, $"Could not find the target {nameof(MenuFlyoutItem)} control."); + + var icon = item.Icon as BitmapIcon; + + Assert.IsNotNull(icon, $"Could not find the {nameof(BitmapIcon)} element in button."); + + Assert.AreEqual(icon.UriSource, new Uri("ms-resource:///Files/Assets/StoreLogo.png"), "Expected ms-resource:///Files/Assets/StoreLogo.png uri."); + Assert.AreEqual(icon.ShowAsMonochrome, false, "Expected icon not to be monochrome"); + } + + [TestCategory("BitmapIconExtensionMarkupExtension")] + [UITestMethod] + public void Test_BitmapIconExtension_MarkupExtension_ProvideImageAndMonochrome() + { + var treeroot = XamlReader.Load(@" + +") as FrameworkElement; + + var button = treeroot.FindChildByName("RootButton") as Button; + + Assert.IsNotNull(button, $"Could not find the {nameof(Button)} control in tree."); + + var item = ((MenuFlyout)button.Flyout)?.Items?.FirstOrDefault() as MenuFlyoutItem; + + Assert.IsNotNull(button, $"Could not find the target {nameof(MenuFlyoutItem)} control."); + + var icon = item.Icon as BitmapIcon; + + Assert.IsNotNull(icon, $"Could not find the {nameof(BitmapIcon)} element in button."); + + Assert.AreEqual(icon.UriSource, new Uri("ms-resource:///Files/Assets/StoreLogo.png"), "Expected ms-resource:///Files/Assets/StoreLogo.png uri."); + Assert.AreEqual(icon.ShowAsMonochrome, true, "Expected icon to be monochrome"); + } + } +} \ No newline at end of file diff --git a/UnitTests/UnitTests.csproj b/UnitTests/UnitTests.csproj index b4208dc4fef..43e0197ecea 100644 --- a/UnitTests/UnitTests.csproj +++ b/UnitTests/UnitTests.csproj @@ -136,6 +136,7 @@ + From 993cdef37ed47e012cb4c94984ae55b6ba602886 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 25 Mar 2020 14:59:16 +0100 Subject: [PATCH 16/34] Removed [Bindable] attribute from markup extensions See #3191 for more info about this --- .../Extensions/Markup/BitmapIconExtension.cs | 2 -- Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs | 2 -- .../Extensions/Markup/FontIconSourceExtension.cs | 2 -- 3 files changed, 6 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs index 68ded4e2cea..1c66370dbab 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs @@ -4,7 +4,6 @@ using System; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Markup; namespace Microsoft.Toolkit.Uwp.UI.Extensions @@ -12,7 +11,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions /// /// Custom which can provide values. /// - [Bindable] [MarkupExtensionReturnType(ReturnType = typeof(BitmapIcon))] public sealed class BitmapIconExtension : MarkupExtension { diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs index 8394c244fea..3b00d4d4412 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs @@ -4,7 +4,6 @@ using Windows.UI.Text; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Markup; using Windows.UI.Xaml.Media; @@ -13,7 +12,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions /// /// Custom which can provide values. /// - [Bindable] [MarkupExtensionReturnType(ReturnType = typeof(FontIcon))] public class FontIconExtension : MarkupExtension { diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs index 6e909bd1cb2..06ee496fc32 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs @@ -4,7 +4,6 @@ using Windows.UI.Text; using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Markup; using Windows.UI.Xaml.Media; @@ -13,7 +12,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions /// /// Custom which can provide values. /// - [Bindable] [MarkupExtensionReturnType(ReturnType = typeof(FontIconSource))] public class FontIconSourceExtension : MarkupExtension { From 0d579646d2042636b3fb998e943553840816afec Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 1 Apr 2020 00:36:18 +0200 Subject: [PATCH 17/34] Added a sample page for the FontIconExtension type --- .../Microsoft.Toolkit.Uwp.SampleApp.csproj | 8 +++++ .../IconExtensions/IconExtensionsPage.xaml | 9 ++++++ .../IconExtensions/IconExtensionsPage.xaml.cs | 30 +++++++++++++++++++ .../IconExtensions/IconExtensionsXaml.bind | 25 ++++++++++++++++ .../SamplePages/samples.json | 11 ++++++- 5 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml create mode 100644 Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml.cs create mode 100644 Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind diff --git a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj index db67c3365e3..96bad297cb0 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj +++ b/Microsoft.Toolkit.Uwp.SampleApp/Microsoft.Toolkit.Uwp.SampleApp.csproj @@ -515,6 +515,9 @@ ImageExLazyLoadingControl.xaml + + IconExtensionsPage.xaml + OnDevicePage.xaml @@ -539,6 +542,7 @@ + @@ -929,6 +933,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + MSBuild:Compile Designer diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml new file mode 100644 index 00000000000..2df0a3366b3 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml @@ -0,0 +1,9 @@ + + + + diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml.cs new file mode 100644 index 00000000000..0311ad04acf --- /dev/null +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml.cs @@ -0,0 +1,30 @@ +// 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.Linq; +using Microsoft.Toolkit.Uwp.UI.Animations.Behaviors; +using Microsoft.Toolkit.Uwp.UI.Extensions; +using Microsoft.Xaml.Interactivity; +using Windows.UI.Xaml; + +namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages +{ + /// + /// A page that shows how to use the offset behavior. + /// + public sealed partial class IconExtensionsPage : IXamlRenderListener + { + /// + /// Initializes a new instance of the class. + /// + public IconExtensionsPage() + { + InitializeComponent(); + } + + public void OnXamlRendered(FrameworkElement control) + { + } + } +} \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind new file mode 100644 index 00000000000..fd494884ee7 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json index 22cef444cca..5ab0981f61c 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json @@ -1093,7 +1093,16 @@ "Icon": "/SamplePages/OnDevice/OnDevice.png", "XamlCodeFile": "OnDeviceXaml.bind", "DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/extensions/OnDeviceMarkup.md" - } + }, + { + "Name": "IconExtensions", + "Type": "IconExtensionsPage", + "About": "Markup extensions to easily create various types of icons.", + "CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension", + "XamlCodeFile": "IconExtensionsXaml.bind", + "Icon": "/Assets/Helpers.png", + "DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/extensions/IconExtensions.md" + } ] }, { From ede72e4c7c6e5107358b83031490dc6ac5e2ae3b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 1 Apr 2020 00:41:55 +0200 Subject: [PATCH 18/34] Added sample for the BitmapIcon extension --- .../IconExtensions/IconExtensionsXaml.bind | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind index fd494884ee7..2e7b5b118ac 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind @@ -20,6 +20,21 @@ + + + + \ No newline at end of file From b783070f7144bca03a36d69dba5e2a44ac8b332c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 1 Apr 2020 01:18:26 +0200 Subject: [PATCH 19/34] Added FontIconSource sample page (not loading) --- .../IconExtensions/IconExtensionsXaml.bind | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind index 2e7b5b118ac..9d4d31cf5e3 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind @@ -21,6 +21,24 @@ + + + + + + + + + + + + From bf098a6c19038e18fece3056a7c9ec96ed874f13 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 1 Apr 2020 01:26:47 +0200 Subject: [PATCH 20/34] =?UTF-8?q?Minor=20code=20style=20tweaks,=20also=20t?= =?UTF-8?q?ests=20work=20now=20=C2=AF\=5F(=E3=83=84)=5F/=C2=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SamplePages/IconExtensions/IconExtensionsXaml.bind | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind index 9d4d31cf5e3..f21cb81db45 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind @@ -26,8 +26,9 @@ Style="{StaticResource BodyTextBlockStyle}"/> + Background="#40000000" + BorderBrush="{ThemeResource ButtonBackgroundBackground}" + Width="300" Margin="12" Height="68"> From bf6a306d0e79b267117f4c182e4c50ce59c918bb Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 3 Apr 2020 00:53:05 +0200 Subject: [PATCH 21/34] Added shallow copy for icon markup extensions --- .../IconExtensions/IconExtensionsPage.xaml | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml index 2df0a3366b3..3dd0ff83adc 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml @@ -3,7 +3,30 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:ex="using:Microsoft.Toolkit.Uwp.UI.Extensions" mc:Ignorable="d"> + + + + + + + + + + + + + + + + From 83e538a1f90224b4c9b75da3353825264f5e6858 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 3 Apr 2020 00:54:00 +0200 Subject: [PATCH 22/34] Fixed a missing resource in the icon markup sample page --- .../SamplePages/IconExtensions/IconExtensionsXaml.bind | 1 - 1 file changed, 1 deletion(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind index f21cb81db45..b86ed27a84f 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind @@ -27,7 +27,6 @@ From 1a524b6c02a51315a7deb0d5a0c94ac5e0ae25b7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 4 Apr 2020 13:23:51 +0200 Subject: [PATCH 23/34] Code refactoring --- .../Markup/Abstract/TextIconExtension.cs | 46 +++++++++++++++++++ .../Extensions/Markup/FontIconExtension.cs | 33 +------------ .../Markup/FontIconSourceExtension.cs | 33 +------------ 3 files changed, 48 insertions(+), 64 deletions(-) create mode 100644 Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs new file mode 100644 index 00000000000..39c70c8398f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs @@ -0,0 +1,46 @@ +// 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 Windows.UI.Text; +using Windows.UI.Xaml.Markup; + +namespace Microsoft.Toolkit.Uwp.UI.Extensions +{ + /// + /// An abstract which to produce text-based icons. + /// + /// The type representing the glyph for the current icon. + public abstract class TextIconExtension : MarkupExtension + { + /// + /// Gets or sets the value representing the icon to display. + /// + public T Glyph { get; set; } + + /// + /// Gets or sets the size of the icon to display. + /// + public double FontSize { get; set; } + + /// + /// Gets or sets the thickness of the icon glyph. + /// + public FontWeight FontWeight { get; set; } = FontWeights.Normal; + + /// + /// Gets or sets the font style for the icon glyph. + /// + public FontStyle FontStyle { get; set; } = FontStyle.Normal; + + /// + /// Gets or sets a value indicating whether automatic text enlargement, to reflect the system text size setting, is enabled. + /// + public bool IsTextScaleFactorEnabled { get; set; } + + /// + /// Gets or sets a value indicating whether the icon is mirrored when the flow direction is right to left. + /// + public bool MirroredWhenRightToLeft { get; set; } + } +} diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs index 3b00d4d4412..5a883e3d890 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Windows.UI.Text; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Markup; using Windows.UI.Xaml.Media; @@ -13,43 +12,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions /// Custom which can provide values. /// [MarkupExtensionReturnType(ReturnType = typeof(FontIcon))] - public class FontIconExtension : MarkupExtension + public class FontIconExtension : TextIconExtension { - /// - /// Gets or sets the representing the icon to display. - /// - public string Glyph { get; set; } - - /// - /// Gets or sets the size of the icon to display. - /// - public double FontSize { get; set; } - /// /// Gets or sets the font family to use to display the icon. If , "Segoe MDL2 Assets" will be used. /// public FontFamily FontFamily { get; set; } - /// - /// Gets or sets the thickness of the icon glyph. - /// - public FontWeight FontWeight { get; set; } = FontWeights.Normal; - - /// - /// Gets or sets the font style for the icon glyph. - /// - public FontStyle FontStyle { get; set; } = FontStyle.Normal; - - /// - /// Gets or sets a value indicating whether automatic text enlargement, to reflect the system text size setting, is enabled. - /// - public bool IsTextScaleFactorEnabled { get; set; } - - /// - /// Gets or sets a value indicating whether the icon is mirrored when the flow direction is right to left. - /// - public bool MirroredWhenRightToLeft { get; set; } - /// protected override object ProvideValue() { diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs index 06ee496fc32..fcfd825322a 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Windows.UI.Text; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Markup; using Windows.UI.Xaml.Media; @@ -13,43 +12,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions /// Custom which can provide values. /// [MarkupExtensionReturnType(ReturnType = typeof(FontIconSource))] - public class FontIconSourceExtension : MarkupExtension + public class FontIconSourceExtension : TextIconExtension { - /// - /// Gets or sets the representing the icon to display. - /// - public string Glyph { get; set; } - - /// - /// Gets or sets the size of the icon to display. - /// - public double FontSize { get; set; } - /// /// Gets or sets the font family to use to display the icon. If , "Segoe MDL2 Assets" will be used. /// public FontFamily FontFamily { get; set; } - /// - /// Gets or sets the thickness of the icon glyph. - /// - public FontWeight FontWeight { get; set; } = FontWeights.Normal; - - /// - /// Gets or sets the font style for the icon glyph. - /// - public FontStyle FontStyle { get; set; } = FontStyle.Normal; - - /// - /// Gets or sets a value indicating whether automatic text enlargement, to reflect the system text size setting, is enabled. - /// - public bool IsTextScaleFactorEnabled { get; set; } - - /// - /// Gets or sets a value indicating whether the icon is mirrored when the flow direction is right to left. - /// - public bool MirroredWhenRightToLeft { get; set; } - /// protected override object ProvideValue() { From d706a40efb9f44eabb77525d47bd1355eb65e6b3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 4 Apr 2020 13:33:30 +0200 Subject: [PATCH 24/34] Updated samples page --- .../IconExtensions/IconExtensionsPage.xaml | 4 ++ .../IconExtensions/IconExtensionsXaml.bind | 10 ++++ .../Extensions/Markup/SymbolIconExtension.cs | 50 +++++++++++++++++++ .../Microsoft.Toolkit.Uwp.UI.csproj | 1 + 4 files changed, 65 insertions(+) create mode 100644 Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml index 3dd0ff83adc..7d97129b77b 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml @@ -12,6 +12,10 @@ + + + + diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind index b86ed27a84f..9f910f8bb37 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind @@ -21,6 +21,16 @@ + + + + + + + + diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs new file mode 100644 index 00000000000..8b2c5491b1a --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs @@ -0,0 +1,50 @@ +// 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; +using Windows.UI.Xaml.Media; + +namespace Microsoft.Toolkit.Uwp.UI.Extensions +{ + /// + /// Custom which can provide symbol-baased values. + /// + [MarkupExtensionReturnType(ReturnType = typeof(FontIcon))] + public class SymbolIconExtension : TextIconExtension + { + [ThreadStatic] + private static FontFamily segoeMDL2AssetsFontFamily; + + /// + /// Gets the reusable "Segoe MDL2 Assets" instance. + /// + private static FontFamily SegoeMDL2AssetsFontFamily + { + get => segoeMDL2AssetsFontFamily ??= new FontFamily("Segoe MDL2 Assets"); + } + + /// + protected override object ProvideValue() + { + var fontIcon = new FontIcon + { + Glyph = unchecked((char)Glyph).ToString(), + FontFamily = SegoeMDL2AssetsFontFamily, + FontWeight = FontWeight, + FontStyle = FontStyle, + IsTextScaleFactorEnabled = IsTextScaleFactorEnabled, + MirroredWhenRightToLeft = MirroredWhenRightToLeft + }; + + if (FontSize > 0) + { + fontIcon.FontSize = FontSize; + } + + return fontIcon; + } + } +} diff --git a/Microsoft.Toolkit.Uwp.UI/Microsoft.Toolkit.Uwp.UI.csproj b/Microsoft.Toolkit.Uwp.UI/Microsoft.Toolkit.Uwp.UI.csproj index 9d61f8094a9..1eb62edce4f 100644 --- a/Microsoft.Toolkit.Uwp.UI/Microsoft.Toolkit.Uwp.UI.csproj +++ b/Microsoft.Toolkit.Uwp.UI/Microsoft.Toolkit.Uwp.UI.csproj @@ -2,6 +2,7 @@ uap10.0.16299 + 8.0 Windows Community Toolkit UI This library provides UI components, such as XAML extensions, helpers, converters and more. It is part of the Windows Community Toolkit. From 0925cf1a9360f6e2adaa8245a11a556dc9393602 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 4 Apr 2020 13:38:18 +0200 Subject: [PATCH 25/34] Code refactoring, minor optimizations --- .../Markup/Abstract/TextIconExtension.cs | 19 ++++++++++++------ .../Markup/Abstract/TextIconExtension{T}.cs | 20 +++++++++++++++++++ .../Extensions/Markup/FontIconExtension.cs | 2 +- .../Markup/FontIconSourceExtension.cs | 2 +- .../Extensions/Markup/SymbolIconExtension.cs | 13 ------------ 5 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension{T}.cs diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs index 39c70c8398f..5d8b113d49d 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs @@ -2,26 +2,33 @@ // 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.Text; using Windows.UI.Xaml.Markup; +using Windows.UI.Xaml.Media; namespace Microsoft.Toolkit.Uwp.UI.Extensions { /// /// An abstract which to produce text-based icons. /// - /// The type representing the glyph for the current icon. - public abstract class TextIconExtension : MarkupExtension + public abstract class TextIconExtension : MarkupExtension { /// - /// Gets or sets the value representing the icon to display. + /// Gets or sets the size of the icon to display. /// - public T Glyph { get; set; } + public double FontSize { get; set; } + + [ThreadStatic] + private static FontFamily segoeMDL2AssetsFontFamily; /// - /// Gets or sets the size of the icon to display. + /// Gets the reusable "Segoe MDL2 Assets" instance. /// - public double FontSize { get; set; } + protected static FontFamily SegoeMDL2AssetsFontFamily + { + get => segoeMDL2AssetsFontFamily ??= new FontFamily("Segoe MDL2 Assets"); + } /// /// Gets or sets the thickness of the icon glyph. diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension{T}.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension{T}.cs new file mode 100644 index 00000000000..a7944e4058f --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension{T}.cs @@ -0,0 +1,20 @@ +// 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 Windows.UI.Xaml.Markup; + +namespace Microsoft.Toolkit.Uwp.UI.Extensions +{ + /// + /// 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 5a883e3d890..1a8f4af5631 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs @@ -25,7 +25,7 @@ protected override object ProvideValue() var fontIcon = new FontIcon { Glyph = Glyph, - FontFamily = FontFamily ?? new FontFamily("Segoe MDL2 Assets"), + FontFamily = FontFamily ?? SegoeMDL2AssetsFontFamily, FontWeight = FontWeight, FontStyle = FontStyle, IsTextScaleFactorEnabled = IsTextScaleFactorEnabled, diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs index fcfd825322a..a77e86f38cd 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs @@ -25,7 +25,7 @@ protected override object ProvideValue() var fontIcon = new FontIconSource { Glyph = Glyph, - FontFamily = FontFamily ?? new FontFamily("Segoe MDL2 Assets"), + FontFamily = FontFamily ?? SegoeMDL2AssetsFontFamily, FontWeight = FontWeight, FontStyle = FontStyle, IsTextScaleFactorEnabled = IsTextScaleFactorEnabled, diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs index 8b2c5491b1a..638516a38c1 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs @@ -2,10 +2,8 @@ // 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; -using Windows.UI.Xaml.Media; namespace Microsoft.Toolkit.Uwp.UI.Extensions { @@ -15,17 +13,6 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions [MarkupExtensionReturnType(ReturnType = typeof(FontIcon))] public class SymbolIconExtension : TextIconExtension { - [ThreadStatic] - private static FontFamily segoeMDL2AssetsFontFamily; - - /// - /// Gets the reusable "Segoe MDL2 Assets" instance. - /// - private static FontFamily SegoeMDL2AssetsFontFamily - { - get => segoeMDL2AssetsFontFamily ??= new FontFamily("Segoe MDL2 Assets"); - } - /// protected override object ProvideValue() { From 69e5687e8d97856cc121e9f6277f36bd7b1a8c27 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 4 Apr 2020 13:41:43 +0200 Subject: [PATCH 26/34] Added SymbolIconSourceExtension type --- .../Markup/SymbolIconSourceExtension.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs new file mode 100644 index 00000000000..5f64dd5ddd5 --- /dev/null +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.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 Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Markup; + +namespace Microsoft.Toolkit.Uwp.UI.Extensions +{ + /// + /// Custom which can provide symbol-baased values. + /// + [MarkupExtensionReturnType(ReturnType = typeof(FontIconSource))] + public class SymbolIconSourceExtension : TextIconExtension + { + /// + protected override object ProvideValue() + { + var fontIcon = new FontIconSource + { + Glyph = unchecked((char)Glyph).ToString(), + FontFamily = SegoeMDL2AssetsFontFamily, + FontWeight = FontWeight, + FontStyle = FontStyle, + IsTextScaleFactorEnabled = IsTextScaleFactorEnabled, + MirroredWhenRightToLeft = MirroredWhenRightToLeft + }; + + if (FontSize > 0) + { + fontIcon.FontSize = FontSize; + } + + return fontIcon; + } + } +} From fecdc53f72708add39f2d9d1f2f3397af77f78c7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 4 Apr 2020 13:42:38 +0200 Subject: [PATCH 27/34] Added SymbolIconSourceExtension sample --- .../IconExtensions/IconExtensionsPage.xaml | 4 +--- .../IconExtensions/IconExtensionsXaml.bind | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml index 7d97129b77b..2655dda17d8 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml @@ -10,9 +10,6 @@ - - - @@ -20,6 +17,7 @@ + diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind index 9f910f8bb37..48507ef0c43 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 3f4a5c8693224dc24952dd6225ce903d4b600b46 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 4 Apr 2020 13:48:49 +0200 Subject: [PATCH 28/34] Added foreground property to icon extensions --- .../Extensions/Markup/Abstract/TextIconExtension.cs | 5 +++++ .../Extensions/Markup/FontIconExtension.cs | 5 +++++ .../Extensions/Markup/FontIconSourceExtension.cs | 5 +++++ .../Extensions/Markup/SymbolIconExtension.cs | 5 +++++ .../Extensions/Markup/SymbolIconSourceExtension.cs | 5 +++++ 5 files changed, 25 insertions(+) diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs index 5d8b113d49d..4640b476687 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension.cs @@ -40,6 +40,11 @@ protected static FontFamily SegoeMDL2AssetsFontFamily /// public FontStyle FontStyle { get; set; } = FontStyle.Normal; + /// + /// Gets or sets the foreground for the icon. + /// + public Brush Foreground { get; set; } + /// /// Gets or sets a value indicating whether automatic text enlargement, to reflect the system text size setting, is enabled. /// diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs index 1a8f4af5631..1e1c800d442 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs @@ -37,6 +37,11 @@ protected override object ProvideValue() fontIcon.FontSize = FontSize; } + if (Foreground != null) + { + fontIcon.Foreground = Foreground; + } + return fontIcon; } } diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs index a77e86f38cd..af2fe602587 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs @@ -37,6 +37,11 @@ protected override object ProvideValue() fontIcon.FontSize = FontSize; } + if (Foreground != null) + { + fontIcon.Foreground = Foreground; + } + return fontIcon; } } diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs index 638516a38c1..414a33247c6 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs @@ -31,6 +31,11 @@ protected override object ProvideValue() fontIcon.FontSize = FontSize; } + if (Foreground != null) + { + fontIcon.Foreground = Foreground; + } + return fontIcon; } } diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs index 5f64dd5ddd5..f5b4e1725da 100644 --- a/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs +++ b/Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs @@ -31,6 +31,11 @@ protected override object ProvideValue() fontIcon.FontSize = FontSize; } + if (Foreground != null) + { + fontIcon.Foreground = Foreground; + } + return fontIcon; } } From e6ca30de21883ad9169e6e5d0f06cee8d58e3a1b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 22 Apr 2020 19:57:45 +0200 Subject: [PATCH 29/34] Fixed a typo in a unit test --- UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs index 57021acb75e..a885603e730 100644 --- a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs +++ b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs @@ -69,7 +69,7 @@ public void Test_FontIconExtension_MarkupExtension_ProvideCustomFontIcon() xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions""> - + ") as FrameworkElement; var button = treeroot.FindChildByName("Check") as AppBarButton; From dae5a496c8300442192e3aa44eb663f28701011c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 22 Apr 2020 20:04:13 +0200 Subject: [PATCH 30/34] Fixed remaining unit tests --- UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs | 2 +- .../Extensions/Test_FontIconSourceExtensionMarkupExtension.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs index a885603e730..a8b7465c587 100644 --- a/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs +++ b/UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs @@ -82,7 +82,7 @@ public void Test_FontIconExtension_MarkupExtension_ProvideCustomFontIcon() Assert.AreEqual(icon.Glyph, "\uE14D", "Expected icon glyph to be E14D."); Assert.AreEqual(icon.FontSize, 7.0, "Expected font size of 7"); - Assert.AreEqual(icon.FontFamily.Source, "Segoe MDL2 Assets", "Expected font family to be Segoe UI"); + Assert.AreEqual(icon.FontFamily.Source, "Segoe MDL2 Assets", "Expected font family to be Segoe MDL2 Assets"); Assert.AreEqual(icon.FontWeight, FontWeights.Bold, "Expected bold font weight"); Assert.AreEqual(icon.FontStyle, FontStyle.Italic, "Expected italic font style"); Assert.AreEqual(icon.IsTextScaleFactorEnabled, true, "Expected IsTextScaleFactorEnabled set to true"); diff --git a/UnitTests/Extensions/Test_FontIconSourceExtensionMarkupExtension.cs b/UnitTests/Extensions/Test_FontIconSourceExtensionMarkupExtension.cs index 1c1c81852a7..0a35c561b15 100644 --- a/UnitTests/Extensions/Test_FontIconSourceExtensionMarkupExtension.cs +++ b/UnitTests/Extensions/Test_FontIconSourceExtensionMarkupExtension.cs @@ -73,7 +73,7 @@ public void Test_FontIconSourceExtension_MarkupExtension_ProvideCustomFontIcon() xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:ex=""using:Microsoft.Toolkit.Uwp.UI.Extensions"" xmlns:controls=""using:UnitTests.Extensions""> - + ") as FrameworkElement; var button = treeroot.FindChildByName("Check") as MockSwipeItem; @@ -86,7 +86,7 @@ public void Test_FontIconSourceExtension_MarkupExtension_ProvideCustomFontIcon() Assert.AreEqual(icon.Glyph, "\uE14D", "Expected icon glyph to be E14D."); Assert.AreEqual(icon.FontSize, 7.0, "Expected font size of 7"); - Assert.AreEqual(icon.FontFamily.Source, "Segoe MDL2 Assets", "Expected font family to be Segoe UI"); + Assert.AreEqual(icon.FontFamily.Source, "Segoe MDL2 Assets", "Expected font family to be Segoe MDL2 Assets"); Assert.AreEqual(icon.FontWeight, FontWeights.Bold, "Expected bold font weight"); Assert.AreEqual(icon.FontStyle, FontStyle.Italic, "Expected italic font style"); Assert.AreEqual(icon.IsTextScaleFactorEnabled, true, "Expected IsTextScaleFactorEnabled set to true"); From 78f4d7623d906675f7b4780a76277edbccc9cd3d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 12 May 2020 18:44:58 +0200 Subject: [PATCH 31/34] Removed unnecessary using directives --- .../SamplePages/Connected Animations/Pages/ThirdPage.xaml.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Connected Animations/Pages/ThirdPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Connected Animations/Pages/ThirdPage.xaml.cs index a37623e4fd2..d7ec8716591 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Connected Animations/Pages/ThirdPage.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Connected Animations/Pages/ThirdPage.xaml.cs @@ -3,9 +3,6 @@ // See the LICENSE file in the project root for more information. using Microsoft.Toolkit.Uwp.SampleApp.Data; -using Microsoft.Toolkit.Uwp.SampleApp.Models; -using System; -using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; From db20516409a3d507f75a6cf63da488902848dd88 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 12 May 2020 21:15:46 +0200 Subject: [PATCH 32/34] Fixed BitmapIcon and FontIcon extension tests --- UnitTests/Properties/UnitTestApp.rd.xml | 12 +++++++++- UnitTests/UnitTestApp.xaml | 30 +++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/UnitTests/Properties/UnitTestApp.rd.xml b/UnitTests/Properties/UnitTestApp.rd.xml index 6e2afca77fe..be5c4987ee3 100644 --- a/UnitTests/Properties/UnitTestApp.rd.xml +++ b/UnitTests/Properties/UnitTestApp.rd.xml @@ -22,9 +22,19 @@ the application package. The asterisks are not wildcards. --> - + + + + + + + + + + + \ No newline at end of file diff --git a/UnitTests/UnitTestApp.xaml b/UnitTests/UnitTestApp.xaml index c38cc7fbf26..1ed3af02693 100644 --- a/UnitTests/UnitTestApp.xaml +++ b/UnitTests/UnitTestApp.xaml @@ -1,5 +1,31 @@  + xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions" + RequestedTheme="Light" > + + + + + + + + + + + + + + + + + + + + From 364ea74a6ec2ed3425ed419cc246b520b74b6a81 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 12 May 2020 21:22:28 +0200 Subject: [PATCH 33/34] Fixed FontIconSource extension tests --- UnitTests/UnitTestApp.xaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/UnitTests/UnitTestApp.xaml b/UnitTests/UnitTestApp.xaml index 1ed3af02693..f9e9631c047 100644 --- a/UnitTests/UnitTestApp.xaml +++ b/UnitTests/UnitTestApp.xaml @@ -2,6 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions" + xmlns:unitTestExtensions="using:UnitTests.Extensions" RequestedTheme="Light" > @@ -11,14 +12,13 @@ - - - - - - - - + + +