Skip to content

Commit 6dc0314

Browse files
Merge pull request #3334 from Sergio0694/feature/bitmapiconsource-extension
BitmapIconSource extension
2 parents 70ed20e + ae1dfcb commit 6dc0314

File tree

9 files changed

+95
-35
lines changed

9 files changed

+95
-35
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsPage.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010

1111
<CommandBar>
1212
<AppBarButton Icon="{ex:FontIcon Glyph=&#xE102;}"/>
13-
<AppBarButton Icon="{ex:SymbolIcon Glyph=Play}"/>
13+
<AppBarButton Icon="{ex:SymbolIcon Symbol=Play}"/>
1414
</CommandBar>
1515

1616
<SwipeControl>
1717
<SwipeControl.LeftItems>
1818
<SwipeItems Mode="Reveal">
1919
<SwipeItem Text="Accept" IconSource="{ex:FontIconSource Glyph=&#xE10B;}"/>
20-
<SwipeItem Text="Play" IconSource="{ex:SymbolIconSource Glyph=Play}"/>
20+
<SwipeItem Text="Play" IconSource="{ex:SymbolIconSource Symbol=Play}"/>
21+
<SwipeItem IconSource="{ex:BitmapIconSource Source=/Assets/ToolkitLogo.png}"/>
2122
</SwipeItems>
2223
</SwipeControl.LeftItems>
2324
</SwipeControl>

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/IconExtensions/IconExtensionsXaml.bind

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
Style="{StaticResource BodyTextBlockStyle}"/>
2727

2828
<CommandBar>
29-
<AppBarButton Icon="{ex:SymbolIcon Glyph=Play}"/>
30-
<AppBarButton Icon="{ex:SymbolIcon Glyph=Pause}"/>
31-
<AppBarButton Icon="{ex:SymbolIcon Glyph=Home}"/>
29+
<AppBarButton Icon="{ex:SymbolIcon Symbol=Play}"/>
30+
<AppBarButton Icon="{ex:SymbolIcon Symbol=Pause}"/>
31+
<AppBarButton Icon="{ex:SymbolIcon Symbol=Home}"/>
3232
</CommandBar>
3333

3434
<TextBlock Text="Use the FontIconSource extension to create FontIconSource items from custom glyphs."
@@ -49,6 +49,24 @@
4949
HorizontalAlignment="Center" VerticalAlignment="Center"/>
5050
</SwipeControl>
5151

52+
<TextBlock Text="Use the BitmapIconSource extension to create BitmapIconSource items from image paths."
53+
TextWrapping="Wrap"
54+
Style="{StaticResource BodyTextBlockStyle}"/>
55+
56+
<SwipeControl BorderThickness="1"
57+
Background="#40000000"
58+
Width="300" Margin="12" Height="68">
59+
<SwipeControl.LeftItems>
60+
<SwipeItems Mode="Reveal">
61+
<SwipeItem IconSource="{ex:BitmapIconSource Source=/Assets/ToolkitLogo.png}"/>
62+
<SwipeItem IconSource="{ex:BitmapIconSource Source=/Assets/mslogo.png}"/>
63+
</SwipeItems>
64+
</SwipeControl.LeftItems>
65+
<TextBlock Text="Swipe Right"
66+
Margin="12"
67+
HorizontalAlignment="Center" VerticalAlignment="Center"/>
68+
</SwipeControl>
69+
5270
<TextBlock Text="Use the SymbolIconSource extension to create FontIconSource items from known symbols."
5371
TextWrapping="Wrap"
5472
Style="{StaticResource BodyTextBlockStyle}"/>
@@ -58,8 +76,8 @@
5876
Width="300" Margin="12" Height="68">
5977
<SwipeControl.LeftItems>
6078
<SwipeItems Mode="Reveal">
61-
<SwipeItem Text="Accept" IconSource="{ex:FontIconSource Glyph=Accept}"/>
62-
<SwipeItem Text="Flag" IconSource="{ex:FontIconSource Glyph=Flag}"/>
79+
<SwipeItem Text="Accept" IconSource="{ex:SymbolIconSource Symbol=Accept}"/>
80+
<SwipeItem Text="Flag" IconSource="{ex:SymbolIconSource Symbol=Flag}"/>
6381
</SwipeItems>
6482
</SwipeControl.LeftItems>
6583
<TextBlock Text="Swipe Right"

Microsoft.Toolkit.Uwp.UI/Extensions/Markup/Abstract/TextIconExtension{T}.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Windows.UI.Xaml.Controls;
7+
using Windows.UI.Xaml.Markup;
8+
9+
namespace Microsoft.Toolkit.Uwp.UI.Extensions
10+
{
11+
/// <summary>
12+
/// Custom <see cref="MarkupExtension"/> which can provide <see cref="BitmapIconSource"/> values.
13+
/// </summary>
14+
[MarkupExtensionReturnType(ReturnType = typeof(BitmapIconSource))]
15+
public sealed class BitmapIconSourceExtension : MarkupExtension
16+
{
17+
/// <summary>
18+
/// Gets or sets the <see cref="Uri"/> representing the image to display.
19+
/// </summary>
20+
public Uri Source { get; set; }
21+
22+
/// <summary>
23+
/// Gets or sets a value indicating whether to display the icon as monochrome.
24+
/// </summary>
25+
public bool ShowAsMonochrome { get; set; }
26+
27+
/// <inheritdoc/>
28+
protected override object ProvideValue()
29+
{
30+
return new BitmapIconSource
31+
{
32+
ShowAsMonochrome = ShowAsMonochrome,
33+
UriSource = Source
34+
};
35+
}
36+
}
37+
}

Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconExtension.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
1212
/// Custom <see cref="MarkupExtension"/> which can provide <see cref="FontIcon"/> values.
1313
/// </summary>
1414
[MarkupExtensionReturnType(ReturnType = typeof(FontIcon))]
15-
public class FontIconExtension : TextIconExtension<string>
15+
public class FontIconExtension : TextIconExtension
1616
{
17+
/// <summary>
18+
/// Gets or sets the <see cref="string"/> value representing the icon to display.
19+
/// </summary>
20+
public string Glyph { get; set; }
21+
1722
/// <summary>
1823
/// Gets or sets the font family to use to display the icon. If <see langword="null"/>, "Segoe MDL2 Assets" will be used.
1924
/// </summary>

Microsoft.Toolkit.Uwp.UI/Extensions/Markup/FontIconSourceExtension.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
1212
/// Custom <see cref="MarkupExtension"/> which can provide <see cref="FontIconSource"/> values.
1313
/// </summary>
1414
[MarkupExtensionReturnType(ReturnType = typeof(FontIconSource))]
15-
public class FontIconSourceExtension : TextIconExtension<string>
15+
public class FontIconSourceExtension : TextIconExtension
1616
{
17+
/// <summary>
18+
/// Gets or sets the <see cref="string"/> value representing the icon to display.
19+
/// </summary>
20+
public string Glyph { get; set; }
21+
1722
/// <summary>
1823
/// Gets or sets the font family to use to display the icon. If <see langword="null"/>, "Segoe MDL2 Assets" will be used.
1924
/// </summary>

Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconExtension.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
1111
/// Custom <see cref="MarkupExtension"/> which can provide symbol-baased <see cref="FontIcon"/> values.
1212
/// </summary>
1313
[MarkupExtensionReturnType(ReturnType = typeof(FontIcon))]
14-
public class SymbolIconExtension : TextIconExtension<Symbol>
14+
public class SymbolIconExtension : TextIconExtension
1515
{
16+
/// <summary>
17+
/// Gets or sets the <see cref="Windows.UI.Xaml.Controls.Symbol"/> value representing the icon to display.
18+
/// </summary>
19+
public Symbol Symbol { get; set; }
20+
1621
/// <inheritdoc/>
1722
protected override object ProvideValue()
1823
{
1924
var fontIcon = new FontIcon
2025
{
21-
Glyph = unchecked((char)Glyph).ToString(),
26+
Glyph = unchecked((char)Symbol).ToString(),
2227
FontFamily = SegoeMDL2AssetsFontFamily,
2328
FontWeight = FontWeight,
2429
FontStyle = FontStyle,

Microsoft.Toolkit.Uwp.UI/Extensions/Markup/SymbolIconSourceExtension.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ namespace Microsoft.Toolkit.Uwp.UI.Extensions
1111
/// Custom <see cref="MarkupExtension"/> which can provide symbol-baased <see cref="FontIconSource"/> values.
1212
/// </summary>
1313
[MarkupExtensionReturnType(ReturnType = typeof(FontIconSource))]
14-
public class SymbolIconSourceExtension : TextIconExtension<Symbol>
14+
public class SymbolIconSourceExtension : TextIconExtension
1515
{
16+
/// <summary>
17+
/// Gets or sets the <see cref="Windows.UI.Xaml.Controls.Symbol"/> value representing the icon to display.
18+
/// </summary>
19+
public Symbol Symbol { get; set; }
20+
1621
/// <inheritdoc/>
1722
protected override object ProvideValue()
1823
{
1924
var fontIcon = new FontIconSource
2025
{
21-
Glyph = unchecked((char)Glyph).ToString(),
26+
Glyph = unchecked((char)Symbol).ToString(),
2227
FontFamily = SegoeMDL2AssetsFontFamily,
2328
FontWeight = FontWeight,
2429
FontStyle = FontStyle,

UnitTests/UnitTests.UWP/UnitTestApp.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<!-- Workarounds for .NET Native issue in unit tests -->
1010
<CommandBar x:Key="DummyCommandBar">
1111
<AppBarButton Icon="{extensions:FontIcon Glyph=&#xE102;}"/>
12-
<AppBarButton Icon="{extensions:SymbolIcon Glyph=Play}"/>
12+
<AppBarButton Icon="{extensions:SymbolIcon Symbol=Play}"/>
1313
</CommandBar>
1414

1515
<unitTestExtensions:MockSwipeItem
@@ -18,7 +18,11 @@
1818

1919
<unitTestExtensions:MockSwipeItem
2020
x:Key="DummySwipeControl2"
21-
IconSource="{extensions:SymbolIconSource Glyph=Play}"/>
21+
IconSource="{extensions:SymbolIconSource Symbol=Play}"/>
22+
23+
<unitTestExtensions:MockSwipeItem
24+
x:Key="DummySwipeControl3"
25+
IconSource="{extensions:BitmapIconSource Source=/Assets/StoreLogo.png}"/>
2226

2327
<Button x:Key="DummyButton">
2428
<Button.Flyout>

0 commit comments

Comments
 (0)