- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.4k
BitmapIcon markup extension #3130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Closed
      
      
            Sergio0694
  wants to merge
  30
  commits into
  CommunityToolkit:master
from
Sergio0694:feature/bitmap-icon-extension
  
      
      
   
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            30 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      3057376
              
                Added FontIcon markup extension
              
              
                Sergio0694 728f1ce
              
                Removed unnecessary using directives
              
              
                Sergio0694 800efba
              
                Renamed the FontIcon markup extension
              
              
                Sergio0694 c2f00be
              
                Added FontIcon tests
              
              
                Sergio0694 4493ffc
              
                Fixed a typo in the test XAML
              
              
                Sergio0694 6418ba5
              
                Merge branch 'master' into feature/font-icon-extension
              
              
                michael-hawker e8d4309
              
                Update UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs
              
              
                Sergio0694 6638416
              
                Update UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs
              
              
                Sergio0694 452a276
              
                Update UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs
              
              
                Sergio0694 5577118
              
                Added new FontIcon properties
              
              
                Sergio0694 9018d88
              
                Merge branch 'feature/font-icon-extension' of https://github.com/Serg…
              
              
                Sergio0694 870306c
              
                Added more tests for the new properties
              
              
                Sergio0694 c6d6023
              
                Added FontIconSourceExtension
              
              
                Sergio0694 e90b0eb
              
                Added BitmapIconExtension
              
              
                Sergio0694 8dda65e
              
                Merge branch 'master' into feature/bitmap-icon-extension
              
              
                Sergio0694 cea30df
              
                Merge branch 'master' into feature/font-icon-source-extension
              
              
                Sergio0694 1b34996
              
                Merge branch 'master' into feature/font-icon-extension
              
              
                Sergio0694 23dcec0
              
                Merge branch 'master' into feature/bitmap-icon-extension
              
              
                Sergio0694 63c2b6e
              
                Merge branch 'master' into feature/font-icon-source-extension
              
              
                Sergio0694 96b22d4
              
                Merge branch 'master' into feature/font-icon-extension
              
              
                Sergio0694 7d6f9ec
              
                Merge branch 'master' into feature/bitmap-icon-extension
              
              
                Sergio0694 91947c1
              
                Merge branch 'master' into feature/font-icon-source-extension
              
              
                Sergio0694 0d8f538
              
                Added tests for the FontIconSource extension
              
              
                Sergio0694 1af9349
              
                Fixed namespace for BitmapIconExtension type
              
              
                Sergio0694 bdcfd9a
              
                Added tests for BitmapIconExtension type
              
              
                Sergio0694 88844c1
              
                Merge branch 'master' into feature/bitmap-icon-extension
              
              
                Sergio0694 d0421d8
              
                Merge branch 'master' into feature/font-icon-source-extension
              
              
                Sergio0694 1d9ad41
              
                Merge branch 'master' into feature/font-icon-extension
              
              
                Sergio0694 ae5f94b
              
                Merge pull request #14 from Sergio0694/feature/font-icon-source-exten…
              
              
                Sergio0694 76cfed2
              
                Merge branch 'feature/font-icon-extension' into feature/bitmap-icon-e…
              
              
                Sergio0694 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            39 changes: 39 additions & 0 deletions
          
          39 
        
  Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,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 | ||
| { | ||
| /// <summary> | ||
| /// Custom <see cref="MarkupExtension"/> which can provide <see cref="BitmapIcon"/> values. | ||
| /// </summary> | ||
| [Bindable] | ||
| [MarkupExtensionReturnType(ReturnType = typeof(BitmapIcon))] | ||
| public sealed class BitmapIconExtension : MarkupExtension | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the <see cref="Uri"/> representing the image to display. | ||
| /// </summary> | ||
| public Uri Source { get; set; } | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets a value indicating whether to display the icon as monochrome. | ||
| /// </summary> | ||
| public bool ShowAsMonochrome { get; set; } | ||
|  | ||
| /// <inheritdoc/> | ||
| protected override object ProvideValue() | ||
| { | ||
| return new BitmapIcon | ||
| { | ||
| ShowAsMonochrome = ShowAsMonochrome, | ||
| UriSource = Source | ||
| }; | ||
| } | ||
| } | ||
| } | ||
        
          
          
            76 changes: 76 additions & 0 deletions
          
          76 
        
  Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,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 | ||
| { | ||
| /// <summary> | ||
| /// Custom <see cref="MarkupExtension"/> which can provide <see cref="FontIcon"/> values. | ||
| /// </summary> | ||
| [Bindable] | ||
| [MarkupExtensionReturnType(ReturnType = typeof(FontIcon))] | ||
| public class FontIconExtension : MarkupExtension | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the <see cref="string"/> representing the icon to display. | ||
| /// </summary> | ||
| public string Glyph { get; set; } | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets the size of the icon to display. | ||
| /// </summary> | ||
| public double FontSize { get; set; } | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets the font family to use to display the icon. If <see langword="null"/>, "Segoe MDL2 Assets" will be used. | ||
| /// </summary> | ||
| public FontFamily FontFamily { get; set; } | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets the thickness of the icon glyph. | ||
| /// </summary> | ||
| public FontWeight FontWeight { get; set; } = FontWeights.Normal; | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets the font style for the icon glyph. | ||
| /// </summary> | ||
| public FontStyle FontStyle { get; set; } = FontStyle.Normal; | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets a value indicating whether automatic text enlargement, to reflect the system text size setting, is enabled. | ||
| /// </summary> | ||
| public bool IsTextScaleFactorEnabled { get; set; } | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets a value indicating whether the icon is mirrored when the flow direction is right to left. | ||
| /// </summary> | ||
| public bool MirroredWhenRightToLeft { get; set; } | ||
|  | ||
| /// <inheritdoc/> | ||
| protected override object ProvideValue() | ||
| { | ||
| var fontIcon = new FontIcon | ||
| { | ||
| 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; | ||
| } | ||
| } | ||
| } | 
        
          
          
            76 changes: 76 additions & 0 deletions
          
          76 
        
  Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,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 | ||
| { | ||
| /// <summary> | ||
| /// Custom <see cref="MarkupExtension"/> which can provide <see cref="FontIconSource"/> values. | ||
| /// </summary> | ||
| [Bindable] | ||
| [MarkupExtensionReturnType(ReturnType = typeof(FontIconSource))] | ||
| public class FontIconSourceExtension : MarkupExtension | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the <see cref="string"/> representing the icon to display. | ||
| /// </summary> | ||
| public string Glyph { get; set; } | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets the size of the icon to display. | ||
| /// </summary> | ||
| public double FontSize { get; set; } | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets the font family to use to display the icon. If <see langword="null"/>, "Segoe MDL2 Assets" will be used. | ||
| /// </summary> | ||
| public FontFamily FontFamily { get; set; } | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets the thickness of the icon glyph. | ||
| /// </summary> | ||
| public FontWeight FontWeight { get; set; } = FontWeights.Normal; | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets the font style for the icon glyph. | ||
| /// </summary> | ||
| public FontStyle FontStyle { get; set; } = FontStyle.Normal; | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets a value indicating whether automatic text enlargement, to reflect the system text size setting, is enabled. | ||
| /// </summary> | ||
| public bool IsTextScaleFactorEnabled { get; set; } | ||
|  | ||
| /// <summary> | ||
| /// Gets or sets a value indicating whether the icon is mirrored when the flow direction is right to left. | ||
| /// </summary> | ||
| public bool MirroredWhenRightToLeft { get; set; } | ||
|  | ||
| /// <inheritdoc/> | ||
| 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; | ||
| } | ||
| } | ||
| } | 
  
    
      This file contains hidden or 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 hidden or 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
    
  
  
    
              
        
          
          
            85 changes: 85 additions & 0 deletions
          
          85 
        
  UnitTests/Extensions/Test_BitmapIconExtensionMarkupExtension.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,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(@"<Page | ||
| 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""> | ||
| <Button x:Name=""RootButton""> | ||
| <Button.Flyout> | ||
| <MenuFlyout> | ||
| <MenuFlyoutItem Icon=""{ex:BitmapIcon Source=/Assets/StoreLogo.png}"" /> | ||
|         
                  Sergio0694 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| </MenuFlyout> | ||
| </Button.Flyout> | ||
| </Button> | ||
| </Page>") 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(@"<Page | ||
| 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""> | ||
| <Button x:Name=""RootButton""> | ||
| <Button.Flyout> | ||
| <MenuFlyout> | ||
| <MenuFlyoutItem Icon=""{ex:BitmapIcon Source=/Assets/StoreLogo.png, ShowAsMonochrome=True}"" /> | ||
| </MenuFlyout> | ||
| </Button.Flyout> | ||
| </Button> | ||
| </Page>") 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"); | ||
| } | ||
| } | ||
| } | ||
        
          
          
            92 changes: 92 additions & 0 deletions
          
          92 
        
  UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or 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,92 @@ | ||
| // 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 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(@"<Page | ||
| 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""> | ||
| <AppBarButton x:Name=""Check"" Icon=""{ex:FontIcon Glyph=}""/> | ||
| </Page>") 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(@"<Page | ||
| 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""> | ||
| <AppBarButton x:Name=""Check"" Icon=""{ex:FontIcon Glyph=, FontFamily='Segoe UI'}""/> | ||
| </Page>") 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.FontFamily.Source, "Segoe UI", "Expected font family to be Segoe UI"); | ||
| } | ||
|  | ||
| [TestCategory("FontIconExtensionMarkupExtension")] | ||
| [UITestMethod] | ||
| public void Test_FontIconExtension_MarkupExtension_ProvideCustomFontIcon() | ||
| { | ||
| var treeroot = XamlReader.Load(@"<Page | ||
| 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""> | ||
| <AppBarButton x:Name=""Check"" Icon=""{ex:FontIcon Glyph=, FontSize=7, FontFamily='Segoe UI', FontWeight=Bold, FontStyle=Italic, IsTextScaleFactorEnabled=True, MirroredWhenRightToLeft=True}""/> | ||
| </Page>") 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"); | ||
| } | ||
| } | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be a body-less method:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really a fan of how the body expression looks in small methods returning an object like this, as at a glance it's easy to confuse the brackets under the method with the actual brackets for the method body, when in fact they belong to that constructor instead.
I'd prefer to leave this as is if that's alright, but let me know what you think! 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vgromfeld do you have any pros/cons around the styling of this one way or the other, I know this is a newer feature of C# compared to when the Toolkit started, so I don't think we have any explicit styling guidelines setup for this scenario. Honestly though, I'm fine with either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The body-less generally allows us to remove all the unneeded characters and write more compact code. It might be less natural first but really helps to read the code faster once you get use to it 😀.
VS2019 code style is recommending this approach. It definitively don't worth a full restyling of all the toolkit code but should be more and more considered when writing new code.