Skip to content

FontIcon markup extension #3110

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
3057376
Added FontIcon markup extension
Sergio0694 Jan 25, 2020
728f1ce
Removed unnecessary using directives
Sergio0694 Jan 25, 2020
800efba
Renamed the FontIcon markup extension
Sergio0694 Jan 25, 2020
c2f00be
Added FontIcon tests
Sergio0694 Jan 25, 2020
4493ffc
Fixed a typo in the test XAML
Sergio0694 Jan 26, 2020
6418ba5
Merge branch 'master' into feature/font-icon-extension
michael-hawker Feb 11, 2020
e8d4309
Update UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs
Sergio0694 Feb 12, 2020
6638416
Update UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs
Sergio0694 Feb 12, 2020
452a276
Update UnitTests/Extensions/Test_FontIconExtensionMarkupExtension.cs
Sergio0694 Feb 12, 2020
5577118
Added new FontIcon properties
Sergio0694 Feb 12, 2020
9018d88
Merge branch 'feature/font-icon-extension' of https://github.com/Serg…
Sergio0694 Feb 12, 2020
870306c
Added more tests for the new properties
Sergio0694 Feb 12, 2020
c6d6023
Added FontIconSourceExtension
Sergio0694 Feb 12, 2020
e90b0eb
Added BitmapIconExtension
Sergio0694 Feb 12, 2020
8dda65e
Merge branch 'master' into feature/bitmap-icon-extension
Sergio0694 Feb 12, 2020
cea30df
Merge branch 'master' into feature/font-icon-source-extension
Sergio0694 Feb 12, 2020
1b34996
Merge branch 'master' into feature/font-icon-extension
Sergio0694 Mar 15, 2020
23dcec0
Merge branch 'master' into feature/bitmap-icon-extension
Sergio0694 Mar 15, 2020
63c2b6e
Merge branch 'master' into feature/font-icon-source-extension
Sergio0694 Mar 15, 2020
96b22d4
Merge branch 'master' into feature/font-icon-extension
Sergio0694 Mar 24, 2020
7d6f9ec
Merge branch 'master' into feature/bitmap-icon-extension
Sergio0694 Mar 24, 2020
91947c1
Merge branch 'master' into feature/font-icon-source-extension
Sergio0694 Mar 24, 2020
0d8f538
Added tests for the FontIconSource extension
Sergio0694 Mar 24, 2020
1af9349
Fixed namespace for BitmapIconExtension type
Sergio0694 Mar 24, 2020
bdcfd9a
Added tests for BitmapIconExtension type
Sergio0694 Mar 24, 2020
88844c1
Merge branch 'master' into feature/bitmap-icon-extension
Sergio0694 Mar 24, 2020
d0421d8
Merge branch 'master' into feature/font-icon-source-extension
Sergio0694 Mar 24, 2020
1d9ad41
Merge branch 'master' into feature/font-icon-extension
Sergio0694 Mar 24, 2020
ae5f94b
Merge pull request #14 from Sergio0694/feature/font-icon-source-exten…
Sergio0694 Mar 24, 2020
76cfed2
Merge branch 'feature/font-icon-extension' into feature/bitmap-icon-e…
Sergio0694 Mar 24, 2020
3618cc2
Merge pull request #15 from Sergio0694/feature/bitmap-icon-extension
Sergio0694 Mar 24, 2020
993cdef
Removed [Bindable] attribute from markup extensions
Sergio0694 Mar 25, 2020
329a5bd
Merge branch 'master' into feature/font-icon-extension
Sergio0694 Mar 31, 2020
0d57964
Added a sample page for the FontIconExtension type
Sergio0694 Mar 31, 2020
ede72e4
Added sample for the BitmapIcon extension
Sergio0694 Mar 31, 2020
b783070
Added FontIconSource sample page (not loading)
Sergio0694 Mar 31, 2020
bf098a6
Minor code style tweaks, also tests work now ¯\_(ツ)_/¯
Sergio0694 Mar 31, 2020
843a442
Merge branch 'master' into feature/font-icon-extension
Sergio0694 Apr 1, 2020
117c8f9
Merge branch 'master' into feature/font-icon-extension
Sergio0694 Apr 2, 2020
246a41d
Merge branch 'master' into feature/font-icon-extension
azchohfi Apr 2, 2020
bf6a306
Added shallow copy for icon markup extensions
Sergio0694 Apr 2, 2020
83e538a
Fixed a missing resource in the icon markup sample page
Sergio0694 Apr 2, 2020
1a524b6
Code refactoring
Sergio0694 Apr 4, 2020
d706a40
Updated samples page
Sergio0694 Apr 4, 2020
0925cf1
Code refactoring, minor optimizations
Sergio0694 Apr 4, 2020
69e5687
Added SymbolIconSourceExtension type
Sergio0694 Apr 4, 2020
fecdc53
Added SymbolIconSourceExtension sample
Sergio0694 Apr 4, 2020
3f4a5c8
Added foreground property to icon extensions
Sergio0694 Apr 4, 2020
26c4ec3
Merge branch 'master' into feature/font-icon-extension
Sergio0694 Apr 19, 2020
a44d3b4
Merge branch 'master' into feature/font-icon-extension
Sergio0694 Apr 22, 2020
e6ca30d
Fixed a typo in a unit test
Sergio0694 Apr 22, 2020
dae5a49
Fixed remaining unit tests
Sergio0694 Apr 22, 2020
22392d2
Merge branch 'master' into feature/font-icon-extension
Sergio0694 May 5, 2020
24d8a10
Merge branch 'master' into feature/font-icon-extension
michael-hawker May 5, 2020
875dfd3
Merge branch 'master' into feature/font-icon-extension
michael-hawker May 12, 2020
78f4d76
Removed unnecessary using directives
Sergio0694 May 12, 2020
db20516
Fixed BitmapIcon and FontIcon extension tests
Sergio0694 May 12, 2020
364ea74
Fixed FontIconSource extension tests
Sergio0694 May 12, 2020
c27aa22
Merge branch 'master' into feature/font-icon-extension
Sergio0694 May 12, 2020
5110f5b
Merge branch 'master' into feature/font-icon-extension
Sergio0694 May 13, 2020
48481f1
Merge branch 'master' into feature/font-icon-extension
Sergio0694 May 15, 2020
d9f0395
Merge remote-tracking branch 'upstream/master' into feature/font-icon…
Sergio0694 May 15, 2020
3e80c64
Fixed build errors after merge
Sergio0694 May 15, 2020
6dd7056
Merge branch 'master' into feature/font-icon-extension
Sergio0694 May 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,9 @@
<Compile Include="SamplePages\ImageEx\ImageExLazyLoadingControl.xaml.cs">
<DependentUpon>ImageExLazyLoadingControl.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\IconExtensions\IconExtensionsPage.xaml.cs">
<DependentUpon>IconExtensionsPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\ObservableGroup\ObservableGroupPage.xaml.cs">
<DependentUpon>ObservableGroupPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -581,6 +584,7 @@
<Content Include="SamplePages\Eyedropper\EyedropperXaml.bind" />
<Content Include="SamplePages\Eyedropper\EyedropperCode.bind" />
<Content Include="SamplePages\TokenizingTextBox\TokenizingTextBoxCode.bind" />
<Content Include="SamplePages\IconExtensions\IconExtensionsXaml.bind" />
<Content Include="SamplePages\WrapLayout\WrapLayout.bind" />
<Content Include="SamplePages\StaggeredLayout\StaggeredLayout.bind" />
<Content Include="SamplePages\ObservableGroup\ObservableGroup.bind" />
Expand Down Expand Up @@ -990,6 +994,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\IconExtensions\IconExtensionsPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="SamplePages\ObservableGroup\ObservableGroupPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Page x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.IconExtensionsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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">
<Grid>
<StackPanel>

<CommandBar>
<AppBarButton Icon="{ex:FontIcon Glyph=&#xE102;}"/>
<AppBarButton Icon="{ex:SymbolIcon Glyph=Play}"/>
</CommandBar>

<SwipeControl>
<SwipeControl.LeftItems>
<SwipeItems Mode="Reveal">
<SwipeItem Text="Accept" IconSource="{ex:FontIconSource Glyph=&#xE10B;}"/>
<SwipeItem Text="Play" IconSource="{ex:SymbolIconSource Glyph=Play}"/>
</SwipeItems>
</SwipeControl.LeftItems>
</SwipeControl>

<Button>
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem Icon="{ex:BitmapIcon Source=/Assets/ToolkitLogo.png}" />
</MenuFlyout>
</Button.Flyout>
</Button>
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// A page that shows how to use the offset behavior.
/// </summary>
public sealed partial class IconExtensionsPage : IXamlRenderListener
{
/// <summary>
/// Initializes a new instance of the <see cref="IconExtensionsPage"/> class.
/// </summary>
public IconExtensionsPage()
{
InitializeComponent();
}

public void OnXamlRendered(FrameworkElement control)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages.IconExtensionsPage"
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">
<Grid>
<StackPanel Spacing="8"
HorizontalAlignment="Center"
VerticalAlignment="Center">

<TextBlock Text="Use the FontIcon extension to create FontIcon items from custom glyphs."
TextWrapping="Wrap"
Style="{StaticResource BodyTextBlockStyle}"/>

<CommandBar>
<AppBarButton Icon="{ex:FontIcon Glyph=&#xE102;}"/>
<AppBarButton Icon="{ex:FontIcon Glyph=&#xE103;}"/>
<AppBarButton Icon="{ex:FontIcon Glyph=&#xE10F;}"/>
</CommandBar>

<TextBlock Text="Use the SymbolIcon extension to create FontIcon items from known symbols."
TextWrapping="Wrap"
Style="{StaticResource BodyTextBlockStyle}"/>

<CommandBar>
<AppBarButton Icon="{ex:SymbolIcon Glyph=Play}"/>
<AppBarButton Icon="{ex:SymbolIcon Glyph=Pause}"/>
<AppBarButton Icon="{ex:SymbolIcon Glyph=Home}"/>
</CommandBar>

<TextBlock Text="Use the FontIconSource extension to create FontIconSource items from custom glyphs."
TextWrapping="Wrap"
Style="{StaticResource BodyTextBlockStyle}"/>

<SwipeControl BorderThickness="1"
Background="#40000000"
Width="300" Margin="12" Height="68">
<SwipeControl.LeftItems>
<SwipeItems Mode="Reveal">
<SwipeItem Text="Accept" IconSource="{ex:FontIconSource Glyph=&#xE10B;}"/>
<SwipeItem Text="Flag" IconSource="{ex:FontIconSource Glyph=&#xE129;}"/>
</SwipeItems>
</SwipeControl.LeftItems>
<TextBlock Text="Swipe Right"
Margin="12"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</SwipeControl>

<TextBlock Text="Use the SymbolIconSource extension to create FontIconSource items from known symbols."
TextWrapping="Wrap"
Style="{StaticResource BodyTextBlockStyle}"/>

<SwipeControl BorderThickness="1"
Background="#40000000"
Width="300" Margin="12" Height="68">
<SwipeControl.LeftItems>
<SwipeItems Mode="Reveal">
<SwipeItem Text="Accept" IconSource="{ex:FontIconSource Glyph=Accept}"/>
<SwipeItem Text="Flag" IconSource="{ex:FontIconSource Glyph=Flag}"/>
</SwipeItems>
</SwipeControl.LeftItems>
<TextBlock Text="Swipe Right"
Margin="12"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</SwipeControl>

<TextBlock Text="Use the BitmapIcon extension to create BitmapIcon items from images."
TextWrapping="Wrap"
Style="{StaticResource BodyTextBlockStyle}"/>

<Button Content="Click me!">
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="Toolkit app"
Icon="{ex:BitmapIcon Source=/Assets/ToolkitLogo.png}" />
<MenuFlyoutItem Text="Microsoft"
Icon="{ex:BitmapIcon Source=/Assets/mslogo.png}" />
</MenuFlyout>
</Button.Flyout>
</Button>
</StackPanel>
</Grid>
</Page>
11 changes: 10 additions & 1 deletion Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,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"
}
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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.Text;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;

namespace Microsoft.Toolkit.Uwp.UI.Extensions
{
/// <summary>
/// An abstract <see cref="MarkupExtension"/> which to produce text-based icons.
/// </summary>
public abstract class TextIconExtension : MarkupExtension
{
/// <summary>
/// Gets or sets the size of the icon to display.
/// </summary>
public double FontSize { get; set; }

[ThreadStatic]
private static FontFamily segoeMDL2AssetsFontFamily;

/// <summary>
/// Gets the reusable "Segoe MDL2 Assets" <see cref="FontFamily"/> instance.
/// </summary>
protected static FontFamily SegoeMDL2AssetsFontFamily
{
get => segoeMDL2AssetsFontFamily ??= new FontFamily("Segoe MDL2 Assets");
}

/// <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 the foreground <see cref="Brush"/> for the icon.
/// </summary>
public Brush Foreground { get; set; }

/// <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; }
}
}
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// An abstract <see cref="MarkupExtension"/> which to produce text-based icons.
/// </summary>
/// <typeparam name="T">The type representing the glyph for the current icon.</typeparam>
public abstract class TextIconExtension<T> : TextIconExtension
{
/// <summary>
/// Gets or sets the <typeparamref name="T"/> value representing the icon to display.
/// </summary>
public T Glyph { get; set; }
}
}
37 changes: 37 additions & 0 deletions Microsoft.Toolkit.Uwp.UI/Extensions/Markup/BitmapIconExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;

namespace Microsoft.Toolkit.Uwp.UI.Extensions
{
/// <summary>
/// Custom <see cref="MarkupExtension"/> which can provide <see cref="BitmapIcon"/> values.
/// </summary>
[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
};
}
}
}
48 changes: 48 additions & 0 deletions Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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;
using Windows.UI.Xaml.Media;

namespace Microsoft.Toolkit.Uwp.UI.Extensions
{
/// <summary>
/// Custom <see cref="MarkupExtension"/> which can provide <see cref="FontIcon"/> values.
/// </summary>
[MarkupExtensionReturnType(ReturnType = typeof(FontIcon))]
public class FontIconExtension : TextIconExtension<string>
{
/// <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; }

/// <inheritdoc/>
protected override object ProvideValue()
{
var fontIcon = new FontIcon
{
Glyph = Glyph,
FontFamily = FontFamily ?? SegoeMDL2AssetsFontFamily,
FontWeight = FontWeight,
FontStyle = FontStyle,
IsTextScaleFactorEnabled = IsTextScaleFactorEnabled,
MirroredWhenRightToLeft = MirroredWhenRightToLeft
};

if (FontSize > 0)
{
fontIcon.FontSize = FontSize;
}

if (Foreground != null)
{
fontIcon.Foreground = Foreground;
}

return fontIcon;
}
}
}
Loading