未验证 提交 0424355b 编写于 作者: M Martin Zikmund 提交者: GitHub

Merge pull request #11947 from unoplatform/dev/mazi/iconsourceelement

feat: `IconSourceElement`, refactor all icons
......@@ -9439,6 +9439,8 @@
<Member fullName="System.Threading.Tasks.Task Windows.UI.Xaml.Controls.WebView.LaunchMailto(System.Threading.CancellationToken ct, System.String subject, System.String body, System.String[] to, System.String[] cc, System.String[] bcc)" reason="Should not be public" />
<Member fullName="System.Void Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs..ctor()" reason="Should not be public" />
<!-- END WebView -->
<Member fullName="System.Void Windows.UI.Xaml.Controls.IconElement.OnForegroundChanged(Windows.UI.Xaml.DependencyPropertyChangedEventArgs e)" reason="Should not be public" />
<Member fullName="System.Void Microsoft.UI.Xaml.Controls.Expander.OnContentClipSizeChanged(System.Object sender, Windows.UI.Xaml.SizeChangedEventArgs args)" reason="Should not be public" />
<Member fullName="System.Void Microsoft.UI.Xaml.Controls.Expander.OnContentSizeChanged(System.Object sender, Windows.UI.Xaml.SizeChangedEventArgs args)" reason="Should not be public" />
......
......@@ -1250,6 +1250,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\IconSourceTests\IconSourceElementTests.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\BorderTests\BorderAntiAlias.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
......@@ -5633,6 +5637,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\BitmapIconTests\BitmapIcon_Monochromatic.xaml.cs">
<DependentUpon>BitmapIcon_Monochromatic.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\IconSourceTests\IconSourceElementTests.xaml.cs">
<DependentUpon>IconSourceElementTests.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\Image_Source_Nullify.xaml.cs">
<DependentUpon>Image_Source_Nullify.xaml</DependentUpon>
</Compile>
......
<Page
x:Class="UITests.Windows_UI_Xaml_Controls.IconSourceTests.IconSourceElementTests"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml_Controls.IconSourceTests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel Spacing="8" Padding="20">
<IconSourceElement>
<SymbolIconSource Symbol="Home" />
</IconSourceElement>
<IconSourceElement>
<FontIconSource Glyph="&#xE909;" />
</IconSourceElement>
<IconSourceElement>
<PathIconSource Data="M15.483,20.522C12.747,20.522 10.511,18.286 10.511,15.55 10.511,12.747 12.747,10.511 15.483,10.511 18.253,10.511 20.489,12.747 20.489,15.55 20.489,18.286 18.253,20.522 15.483,20.522z M26.395,12.113C26.228,11.512 25.961,10.878 25.628,10.211 26.262,9.343 26.996,8.475 27.63,7.508 27.83,7.241 27.83,6.94 27.63,6.64 26.829,5.472 25.494,4.271 24.393,3.336 24.126,3.069 23.759,3.069 23.459,3.303L20.655,5.372C20.121,5.105,19.487,4.871,18.92,4.638L18.386,1.1C18.353,0.733,18.086,0.5,17.685,0.5L13.347,0.5C12.947,0.5 12.68,0.733 12.613,1.067 12.346,2.202 12.213,3.503 12.079,4.638 11.479,4.838 10.878,5.071 10.344,5.405L7.641,3.336C7.474,3.203 7.241,3.103 7.107,3.103 6.44,3.103 3.837,6.006 3.336,6.64 3.069,6.974 3.103,7.174 3.37,7.541 4.07,8.475 4.771,9.343 5.439,10.244 5.138,10.878 4.905,11.379 4.704,12.046L1.034,12.58C0.733,12.647,0.5,13.014,0.5,13.347L0.5,17.652C0.5,17.986,0.733,18.286,1.067,18.353L4.604,18.92C4.771,19.521 5.071,20.155 5.372,20.789 4.738,21.69 4.037,22.524 3.37,23.492 3.169,23.792 3.203,24.093 3.37,24.36 4.204,25.528 5.505,26.729 6.606,27.697 6.907,27.964 7.241,27.964 7.541,27.763L10.344,25.694C10.911,25.961,11.512,26.195,12.079,26.395L12.613,29.966C12.647,30.266,12.947,30.566,13.347,30.566L17.685,30.566C18.086,30.566 18.286,30.333 18.386,29.999 18.687,28.865 18.82,27.563 18.954,26.429 19.554,26.228 20.155,25.961 20.722,25.694L23.425,27.797C23.592,27.93 23.792,27.964 23.959,27.964 24.593,27.964 27.229,25.027 27.73,24.393 27.93,24.126 27.897,23.859 27.663,23.525 26.962,22.558 26.262,21.69 25.594,20.722 25.895,20.188 26.128,19.654 26.362,18.987L29.932,18.453C30.266,18.42,30.5,18.053,30.5,17.786L30.5,13.381C30.5,13.08,30.266,12.747,29.932,12.647z" />
</IconSourceElement>
<IconSourceElement Width="20">
<BitmapIconSource UriSource="ms-appx:///Assets/Icons/search.png" />
</IconSourceElement>
</StackPanel>
</Page>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.UI.Samples.Controls;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
namespace UITests.Windows_UI_Xaml_Controls.IconSourceTests;
[Sample("Icons")]
public sealed partial class IconSourceElementTests : Page
{
public IconSourceElementTests()
{
this.InitializeComponent();
}
}
......@@ -5,7 +5,7 @@ using Windows.UI.Xaml.Controls;
namespace UITests.Shared.Windows_UI_Xaml_Controls.TextBlockControl
{
[Sample("TextBlockControl")]
[Sample("TextBlock")]
public sealed partial class Foreground_Brushes : Page
{
public Foreground_Brushes()
......
......@@ -156,6 +156,9 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
[TestMethod]
[RunsOnUIThread]
#if __MACOS__
[Ignore("Randomly fails on macOS")]
#endif
public async Task When_Transitive_Asset_With_Link_Loaded()
{
string url = "ms-appx:///Uno.UI.RuntimeTests/Assets/TransitiveTest/colors300.png";
......@@ -254,6 +257,9 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
[TestMethod]
[RunsOnUIThread]
#if __MACOS__
[Ignore("Randomly fails on macOS")]
#endif
public async Task When_Image_Is_Loaded_From_URL()
{
string decoded_url = "https://nv-assets.azurewebsites.net/tests/images/image with spaces.jpg";
......
using Private.Infrastructure;
using System.Threading.Tasks;
using Uno.UI.RuntimeTests.Helpers;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.Icons;
[TestClass]
[RunsOnUIThread]
public class Given_BitmapIcon
{
[TestMethod]
public async Task When_Themed()
{
var textBlock = new TextBlock() { Text = "test" };
var bitmapIcon = new BitmapIcon() { UriSource = new System.Uri("ms-appx:///Assets/Icons/search.png") };
var stackPanel = new StackPanel()
{
Children =
{
textBlock,
bitmapIcon
}
};
TestServices.WindowHelper.WindowContent = stackPanel;
await TestServices.WindowHelper.WaitForLoaded(stackPanel);
var textBlockBrush = (SolidColorBrush)textBlock.Foreground;
var bitmapIconBrush = (SolidColorBrush)bitmapIcon.Foreground;
Assert.AreEqual(textBlockBrush.Color, bitmapIconBrush.Color);
using (ThemeHelper.UseDarkTheme())
{
textBlockBrush = (SolidColorBrush)textBlock.Foreground;
bitmapIconBrush = (SolidColorBrush)bitmapIcon.Foreground;
Assert.AreEqual(textBlockBrush.Color, bitmapIconBrush.Color);
}
}
[TestMethod]
public async Task When_Themed_Fluent()
{
using (StyleHelper.UseFluentStyles())
{
await When_Themed();
}
}
}
using System;
using MUXControlsTestApp.Utilities;
using Private.Infrastructure;
using System.Threading.Tasks;
using Uno.UI.RuntimeTests.Helpers;
using Windows.UI;
using Windows.UI.Text;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.Icons;
[TestClass]
[RunsOnUIThread]
public class Given_FontIcon
{
[TestMethod]
public void When_Defaults()
{
var fontIcon = new FontIcon();
Assert.AreEqual("", fontIcon.Glyph);
Assert.AreEqual(20.0, fontIcon.FontSize);
Assert.AreNotEqual(new TextBlock().FontFamily.Source, fontIcon.FontFamily.Source);
Assert.AreEqual(FontWeights.Normal.Weight, fontIcon.FontWeight.Weight);
Assert.AreEqual(FontStyle.Normal, fontIcon.FontStyle);
Assert.IsTrue(fontIcon.IsTextScaleFactorEnabled);
}
[TestMethod]
public async Task When_Themed()
{
var textBlock = new TextBlock() { Text = "test" };
var fontIcon = new FontIcon() { Glyph = "\uE890" };
var stackPanel = new StackPanel()
{
Children =
{
textBlock,
fontIcon
}
};
TestServices.WindowHelper.WindowContent = stackPanel;
await TestServices.WindowHelper.WaitForLoaded(stackPanel);
var textBlockBrush = (SolidColorBrush)textBlock.Foreground;
var fontIconBrush = (SolidColorBrush)fontIcon.Foreground;
Assert.AreEqual(textBlockBrush.Color, fontIconBrush.Color);
using (ThemeHelper.UseDarkTheme())
{
textBlockBrush = (SolidColorBrush)textBlock.Foreground;
fontIconBrush = (SolidColorBrush)fontIcon.Foreground;
Assert.AreEqual(textBlockBrush.Color, fontIconBrush.Color);
}
}
[TestMethod]
public async Task When_Themed_Fluent()
{
using (StyleHelper.UseFluentStyles())
{
await When_Themed();
}
}
[TestMethod]
public async Task When_Themed_TextBlock()
{
var textBlock = new TextBlock() { Text = "test" };
var fontIcon = new FontIcon() { Glyph = "\uE890" };
var stackPanel = new StackPanel()
{
Children =
{
textBlock,
fontIcon
}
};
TestServices.WindowHelper.WindowContent = stackPanel;
await TestServices.WindowHelper.WaitForLoaded(stackPanel);
var innerTextBlock = VisualTreeUtils.FindVisualChildByType<TextBlock>(fontIcon);
var textBlockBrush = (SolidColorBrush)textBlock.Foreground;
var fontIconBrush = (SolidColorBrush)innerTextBlock.Foreground;
Assert.AreEqual(textBlockBrush.Color, fontIconBrush.Color);
using (ThemeHelper.UseDarkTheme())
{
textBlockBrush = (SolidColorBrush)textBlock.Foreground;
fontIconBrush = (SolidColorBrush)innerTextBlock.Foreground;
Assert.AreEqual(textBlockBrush.Color, fontIconBrush.Color);
}
fontIcon.Foreground = new SolidColorBrush(Colors.Red);
fontIconBrush = (SolidColorBrush)innerTextBlock.Foreground;
Assert.AreEqual(Colors.Red, fontIconBrush.Color);
}
[TestMethod]
public async Task When_Themed_TextBlock_Fluent()
{
using (StyleHelper.UseFluentStyles())
{
await When_Themed_TextBlock();
}
}
}
using System.Threading.Tasks;
using MUXControlsTestApp.Utilities;
using Private.Infrastructure;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.Icons;
[TestClass]
[RunsOnUIThread]
public class Given_IconSourceElement
{
[TestMethod]
public async Task When_Switch_Sources()
{
// SymbolIconSource
var symbolIconSource = new SymbolIconSource() { Symbol = Symbol.Accept };
var iconSourceElement = new IconSourceElement()
{
IconSource = symbolIconSource
};
TestServices.WindowHelper.WindowContent = iconSourceElement;
await TestServices.WindowHelper.WaitForLoaded(iconSourceElement);
var symbolChild = VisualTreeUtils.FindVisualChildByType<TextBlock>(iconSourceElement);
Assert.IsNotNull(symbolChild);
Assert.AreEqual("\uE10B", symbolChild.Text); //E10B represents Accept symbol
symbolIconSource.Symbol = Symbol.Cancel;
Assert.AreEqual("\uE10A", symbolChild.Text); //E10A represents Cancel symbol
// PathIconSource
var ellipseGeometry = new EllipseGeometry()
{
RadiusX = 20,
RadiusY = 20
};
var pathIconSource = new PathIconSource() { Data = ellipseGeometry };
iconSourceElement.IconSource = pathIconSource;
Path pathChild = null;
await TestServices.WindowHelper.WaitFor(
() => (pathChild = VisualTreeUtils.FindVisualChildByType<Path>(iconSourceElement)) is not null);
Assert.AreEqual(ellipseGeometry, pathChild.Data);
var rectangleGeometry = new RectangleGeometry()
{
Rect = new Windows.Foundation.Rect(0, 0, 20, 20)
};
pathIconSource.Data = rectangleGeometry;
Assert.AreEqual(rectangleGeometry, pathChild.Data);
// FontIconSource
var fontIconSource = new FontIconSource() { Glyph = "\uE909" };
iconSourceElement.IconSource = fontIconSource;
await TestServices.WindowHelper.WaitForIdle();
TextBlock fontIconChild = null;
await TestServices.WindowHelper.WaitFor(
() => (fontIconChild = VisualTreeUtils.FindVisualChildByType<TextBlock>(iconSourceElement)) is not null);
Assert.AreEqual("\uE909", fontIconChild.Text);
fontIconSource.Glyph = "\uE890";
Assert.AreEqual("\uE890", fontIconChild.Text);
// BitmapIconSource
var bitmapIconSource = new BitmapIconSource() { UriSource = new System.Uri("ms-appx:///Assets/Icons/search.png") };
iconSourceElement.IconSource = bitmapIconSource;
await TestServices.WindowHelper.WaitForIdle();
Image bitmapIconChild = null;
await TestServices.WindowHelper.WaitFor(
() => (bitmapIconChild = VisualTreeUtils.FindVisualChildByType<Image>(iconSourceElement)) is not null);
Assert.IsNotNull(bitmapIconChild.Source);
var previousSource = bitmapIconChild.Source;
bitmapIconSource.UriSource = new System.Uri("ms-appx:///Assets/Icon.png");
Assert.AreNotEqual(previousSource, bitmapIconChild.Source);
}
}
using System.Threading.Tasks;
using MUXControlsTestApp.Utilities;
using Private.Infrastructure;
using Uno.UI.RuntimeTests.Helpers;
using Windows.UI;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.Icons;
[TestClass]
[RunsOnUIThread]
public class Given_PathIcon
{
[TestMethod]
public async Task When_Themed()
{
var textBlock = new TextBlock() { Text = "test" };
var ellipseGeometry = new EllipseGeometry()
{
RadiusX = 20,
RadiusY = 20,
};
var pathIcon = new PathIcon() { Data = ellipseGeometry };
var stackPanel = new StackPanel()
{
Children =
{
textBlock,
pathIcon
}
};
TestServices.WindowHelper.WindowContent = stackPanel;
await TestServices.WindowHelper.WaitForLoaded(stackPanel);
var textBlockBrush = (SolidColorBrush)textBlock.Foreground;
var pathIconBrush = (SolidColorBrush)pathIcon.Foreground;
Assert.AreEqual(textBlockBrush.Color, pathIconBrush.Color);
using (ThemeHelper.UseDarkTheme())
{
textBlockBrush = (SolidColorBrush)textBlock.Foreground;
pathIconBrush = (SolidColorBrush)pathIcon.Foreground;
Assert.AreEqual(textBlockBrush.Color, pathIconBrush.Color);
}
}
[TestMethod]
public async Task When_Themed_Fluent()
{
using (StyleHelper.UseFluentStyles())
{
await When_Themed();
}
}
[TestMethod]
public async Task When_Themed_Path()
{
var textBlock = new TextBlock() { Text = "test" };
var ellipseGeometry = new EllipseGeometry()
{
RadiusX = 20,
RadiusY = 20,
};
var pathIcon = new PathIcon() { Data = ellipseGeometry };
var stackPanel = new StackPanel()
{
Children =
{
textBlock,
pathIcon
}
};
TestServices.WindowHelper.WindowContent = stackPanel;
await TestServices.WindowHelper.WaitForLoaded(stackPanel);
var innerPath = VisualTreeUtils.FindVisualChildByType<Path>(pathIcon);
var textBlockBrush = (SolidColorBrush)textBlock.Foreground;
var pathIconBrush = (SolidColorBrush)innerPath.Fill;
Assert.AreEqual(textBlockBrush.Color, pathIconBrush.Color);
using (ThemeHelper.UseDarkTheme())
{
textBlockBrush = (SolidColorBrush)textBlock.Foreground;
pathIconBrush = (SolidColorBrush)innerPath.Fill;
Assert.AreEqual(textBlockBrush.Color, pathIconBrush.Color);
}
pathIcon.Foreground = new SolidColorBrush(Colors.Red);
pathIconBrush = (SolidColorBrush)innerPath.Fill;
Assert.AreEqual(Colors.Red, pathIconBrush.Color);
}
[TestMethod]
public async Task When_Themed_Path_Fluent()
{
using (StyleHelper.UseFluentStyles())
{
await When_Themed_Path();
}
}
}
using System.Threading.Tasks;
using MUXControlsTestApp.Utilities;
using Private.Infrastructure;
using Uno.UI.RuntimeTests.Helpers;
using Windows.UI;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.Icons;
[TestClass]
[RunsOnUIThread]
public class Given_SymbolIcon
{
[TestMethod]
public void When_Defaults()
{
var symbolIcon = new SymbolIcon();
Assert.AreEqual(Symbol.Emoji, symbolIcon.Symbol);
}
[TestMethod]
#if __MACOS__
[Ignore("Currently fails on macOS, part of #9282! epic")]
#endif
public async Task Validate_Size()
{
var symbolIcon = new SymbolIcon() { Symbol = Symbol.Home };
TestServices.WindowHelper.WindowContent = symbolIcon;
await TestServices.WindowHelper.WaitForLoaded(symbolIcon);
Assert.AreEqual(20.0, symbolIcon.ActualWidth);
Assert.AreEqual(20.0, symbolIcon.ActualHeight);
}
[TestMethod]
public async Task When_Themed()
{
var textBlock = new TextBlock() { Text = "test" };
var symbolIcon = new SymbolIcon() { Symbol = Symbol.Home };
var stackPanel = new StackPanel()
{
Children =
{
textBlock,
symbolIcon
}
};
TestServices.WindowHelper.WindowContent = stackPanel;
await TestServices.WindowHelper.WaitForLoaded(stackPanel);
var textBlockBrush = (SolidColorBrush)textBlock.Foreground;
var symbolIconBrush = (SolidColorBrush)symbolIcon.Foreground;
Assert.AreEqual(textBlockBrush.Color, symbolIconBrush.Color);
using (ThemeHelper.UseDarkTheme())
{
textBlockBrush = (SolidColorBrush)textBlock.Foreground;
symbolIconBrush = (SolidColorBrush)symbolIcon.Foreground;
Assert.AreEqual(textBlockBrush.Color, symbolIconBrush.Color);
}
}
[TestMethod]
public async Task When_Themed_Fluent()
{
using (StyleHelper.UseFluentStyles())
{
await When_Themed();
}
}
[TestMethod]
public async Task When_Themed_TextBlock()
{
var textBlock = new TextBlock() { Text = "test" };
var symbolIcon = new SymbolIcon() { Symbol = Symbol.Home };
var stackPanel = new StackPanel()
{
Children =
{
textBlock,
symbolIcon
}
};
TestServices.WindowHelper.WindowContent = stackPanel;
await TestServices.WindowHelper.WaitForLoaded(stackPanel);
var innerTextBlock = VisualTreeUtils.FindVisualChildByType<TextBlock>(symbolIcon);
var textBlockBrush = (SolidColorBrush)textBlock.Foreground;
var symbolIconBrush = (SolidColorBrush)innerTextBlock.Foreground;
Assert.AreEqual(textBlockBrush.Color, symbolIconBrush.Color);
using (ThemeHelper.UseDarkTheme())
{
textBlockBrush = (SolidColorBrush)textBlock.Foreground;
symbolIconBrush = (SolidColorBrush)innerTextBlock.Foreground;
Assert.AreEqual(textBlockBrush.Color, symbolIconBrush.Color);
}
symbolIcon.Foreground = new SolidColorBrush(Colors.Red);
symbolIconBrush = (SolidColorBrush)innerTextBlock.Foreground;
Assert.AreEqual(Colors.Red, symbolIconBrush.Color);
}
[TestMethod]
public async Task When_Themed_TextBlock_Fluent()
{
using (StyleHelper.UseFluentStyles())
{
await When_Themed_TextBlock();
}
}
}
......@@ -13,34 +13,14 @@ namespace Windows.UI.Xaml.Controls
// Skipping already declared property FontSize
// Skipping already declared property FontFamily
// Skipping already declared property IsTextScaleFactorEnabled
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public bool MirroredWhenRightToLeft
{
get
{
return (bool)this.GetValue(MirroredWhenRightToLeftProperty);
}
set
{
this.SetValue(MirroredWhenRightToLeftProperty, value);
}
}
#endif
// Skipping already declared property MirroredWhenRightToLeft
// Skipping already declared property FontFamilyProperty
// Skipping already declared property FontSizeProperty
// Skipping already declared property FontStyleProperty
// Skipping already declared property FontWeightProperty
// Skipping already declared property GlyphProperty
// Skipping already declared property IsTextScaleFactorEnabledProperty
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty MirroredWhenRightToLeftProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(MirroredWhenRightToLeft), typeof(bool),
typeof(global::Windows.UI.Xaml.Controls.FontIcon),
new Windows.UI.Xaml.FrameworkPropertyMetadata(default(bool)));
#endif
// Skipping already declared property MirroredWhenRightToLeftProperty
// Skipping already declared method Windows.UI.Xaml.Controls.FontIcon.FontIcon()
// Forced skipping of method Windows.UI.Xaml.Controls.FontIcon.FontIcon()
// Forced skipping of method Windows.UI.Xaml.Controls.FontIcon.Glyph.get
......
......@@ -2,12 +2,12 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.UI.Xaml.Controls
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented]
#endif
public partial class IconSourceElement : global::Windows.UI.Xaml.Controls.IconElement
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.UI.Xaml.Controls.IconSource IconSource
{
......@@ -21,7 +21,7 @@ namespace Windows.UI.Xaml.Controls
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty IconSourceProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
......@@ -29,7 +29,7 @@ namespace Windows.UI.Xaml.Controls
typeof(global::Windows.UI.Xaml.Controls.IconSourceElement),
new Windows.UI.Xaml.FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Controls.IconSource)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public IconSourceElement()
{
......
......@@ -2,13 +2,13 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.UI.Xaml.Controls
{
#if false || false || false || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
#endif
public partial class PathIcon : global::Windows.UI.Xaml.Controls.IconElement
{
#if false || false || false || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
public global::Windows.UI.Xaml.Media.Geometry Data
{
get
......@@ -21,16 +21,16 @@ namespace Windows.UI.Xaml.Controls
}
}
#endif
#if false || false || false || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
public static global::Windows.UI.Xaml.DependencyProperty DataProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Data), typeof(global::Windows.UI.Xaml.Media.Geometry),
typeof(global::Windows.UI.Xaml.Controls.PathIcon),
new Windows.UI.Xaml.FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Media.Geometry)));
#endif
#if false || false || false || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
public PathIcon()
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Controls.PathIcon", "PathIcon.PathIcon()");
......
......@@ -2,13 +2,13 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.UI.Xaml.Controls
{
#if false || false || NET461 || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
#endif
public partial class SymbolIcon : global::Windows.UI.Xaml.Controls.IconElement
{
#if false || false || NET461 || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
public global::Windows.UI.Xaml.Controls.Symbol Symbol
{
get
......@@ -21,24 +21,24 @@ namespace Windows.UI.Xaml.Controls
}
}
#endif
#if false || false || NET461 || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
public static global::Windows.UI.Xaml.DependencyProperty SymbolProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Symbol), typeof(global::Windows.UI.Xaml.Controls.Symbol),
typeof(global::Windows.UI.Xaml.Controls.SymbolIcon),
new Windows.UI.Xaml.FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Controls.Symbol)));
#endif
#if false || false || NET461 || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
public SymbolIcon( global::Windows.UI.Xaml.Controls.Symbol symbol)
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Controls.SymbolIcon", "SymbolIcon.SymbolIcon(Symbol symbol)");
}
#endif
// Forced skipping of method Windows.UI.Xaml.Controls.SymbolIcon.SymbolIcon(Windows.UI.Xaml.Controls.Symbol)
#if false || false || NET461 || false || false || __NETSTD_REFERENCE__ || false
[global::Uno.NotImplemented("NET461", "__NETSTD_REFERENCE__")]
#if false || false || false || false || false || false || false
[global::Uno.NotImplemented]
public SymbolIcon()
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Controls.SymbolIcon", "SymbolIcon.SymbolIcon()");
......
......@@ -31,7 +31,7 @@ namespace Microsoft.UI.Xaml.Controls
if (!_initialized)
{
// TODO Uno specific - We must add the child element manually.
AddIconElementView(new Grid());
InitializeRootGrid();
_initialized = true;
}
}
......
......@@ -7,62 +7,61 @@ using Windows.Foundation.Metadata;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.UI.Xaml.Controls
namespace Microsoft.UI.Xaml.Controls;
public partial class BitmapIconSource : IconSource
{
public partial class BitmapIconSource : IconSource
public Uri UriSource
{
public Uri UriSource
{
get => (Uri)GetValue(UriSourceProperty);
set => SetValue(UriSourceProperty, value);
}
get => (Uri)GetValue(UriSourceProperty);
set => SetValue(UriSourceProperty, value);
}
public static DependencyProperty UriSourceProperty { get; } =
DependencyProperty.Register(nameof(UriSource), typeof(Uri), typeof(BitmapIconSource), new FrameworkPropertyMetadata(default(Uri), OnPropertyChanged));
public static DependencyProperty UriSourceProperty { get; } =
DependencyProperty.Register(nameof(UriSource), typeof(Uri), typeof(BitmapIconSource), new FrameworkPropertyMetadata(default(Uri), OnPropertyChanged));
public bool ShowAsMonochrome
{
get => (bool)GetValue(ShowAsMonochromeProperty);
set => SetValue(ShowAsMonochromeProperty, value);
}
public bool ShowAsMonochrome
{
get => (bool)GetValue(ShowAsMonochromeProperty);
set => SetValue(ShowAsMonochromeProperty, value);
}
public static DependencyProperty ShowAsMonochromeProperty { get; } =
DependencyProperty.Register(nameof(ShowAsMonochrome), typeof(bool), typeof(BitmapIconSource), new FrameworkPropertyMetadata(true, OnPropertyChanged));
public static DependencyProperty ShowAsMonochromeProperty { get; } =
DependencyProperty.Register(nameof(ShowAsMonochrome), typeof(bool), typeof(BitmapIconSource), new FrameworkPropertyMetadata(true, OnPropertyChanged));
private protected override IconElement CreateIconElementCore()
private protected override IconElement CreateIconElementCore()
{
var bitmapIcon = new BitmapIcon();
if (UriSource != null)
{
var bitmapIcon = new BitmapIcon();
bitmapIcon.UriSource = UriSource;
}
if (UriSource != null)
{
bitmapIcon.UriSource = UriSource;
}
if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.BitmapIcon", "ShowAsMonochrome"))
{
bitmapIcon.ShowAsMonochrome = ShowAsMonochrome;
}
if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.BitmapIcon", "ShowAsMonochrome"))
{
bitmapIcon.ShowAsMonochrome = ShowAsMonochrome;
}
if (Foreground != null)
{
bitmapIcon.Foreground = Foreground;
}
if (Foreground != null)
{
bitmapIcon.Foreground = Foreground;
}
return bitmapIcon;
}
return bitmapIcon;
private protected override DependencyProperty GetIconElementPropertyCore(DependencyProperty sourceProperty)
{
if (sourceProperty == ShowAsMonochromeProperty)
{
return BitmapIcon.ShowAsMonochromeProperty;
}
private protected override DependencyProperty GetIconElementPropertyCore(DependencyProperty sourceProperty)
else if (sourceProperty == UriSourceProperty)
{
if (sourceProperty == ShowAsMonochromeProperty)
{
return BitmapIcon.ShowAsMonochromeProperty;
}
else if (sourceProperty == UriSourceProperty)
{
return BitmapIcon.UriSourceProperty;
}
return base.GetIconElementPropertyCore(sourceProperty);
return BitmapIcon.UriSourceProperty;
}
return base.GetIconElementPropertyCore(sourceProperty);
}
}
......@@ -8,131 +8,130 @@ using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using FontStyle = Windows.UI.Text.FontStyle;
namespace Microsoft.UI.Xaml.Controls
namespace Microsoft.UI.Xaml.Controls;
public partial class FontIconSource : IconSource
{
public partial class FontIconSource : IconSource
public bool MirroredWhenRightToLeft
{
public bool MirroredWhenRightToLeft
{
get => (bool)GetValue(MirroredWhenRightToLeftProperty);
set => SetValue(MirroredWhenRightToLeftProperty, value);
}
get => (bool)GetValue(MirroredWhenRightToLeftProperty);
set => SetValue(MirroredWhenRightToLeftProperty, value);
}
public static DependencyProperty MirroredWhenRightToLeftProperty { get; } =
DependencyProperty.Register(nameof(MirroredWhenRightToLeft), typeof(bool), typeof(FontIconSource), new FrameworkPropertyMetadata(false, OnPropertyChanged));
public static DependencyProperty MirroredWhenRightToLeftProperty { get; } =
DependencyProperty.Register(nameof(MirroredWhenRightToLeft), typeof(bool), typeof(FontIconSource), new FrameworkPropertyMetadata(false, OnPropertyChanged));
public bool IsTextScaleFactorEnabled
{
get => (bool)GetValue(IsTextScaleFactorEnabledProperty);
set => SetValue(IsTextScaleFactorEnabledProperty, value);
}
public bool IsTextScaleFactorEnabled
{
get => (bool)GetValue(IsTextScaleFactorEnabledProperty);
set => SetValue(IsTextScaleFactorEnabledProperty, value);
}
public static DependencyProperty IsTextScaleFactorEnabledProperty { get; } =
DependencyProperty.Register(nameof(IsTextScaleFactorEnabled), typeof(bool), typeof(FontIconSource), new FrameworkPropertyMetadata(true, OnPropertyChanged));
public static DependencyProperty IsTextScaleFactorEnabledProperty { get; } =
DependencyProperty.Register(nameof(IsTextScaleFactorEnabled), typeof(bool), typeof(FontIconSource), new FrameworkPropertyMetadata(true, OnPropertyChanged));
public string Glyph
{
get => (string)GetValue(GlyphProperty);
set => SetValue(GlyphProperty, value);
}
public string Glyph
{
get => (string)GetValue(GlyphProperty);
set => SetValue(GlyphProperty, value);
}
public static DependencyProperty GlyphProperty { get; } =
DependencyProperty.Register(nameof(Glyph), typeof(string), typeof(FontIconSource), new FrameworkPropertyMetadata(string.Empty, OnPropertyChanged));
public static DependencyProperty GlyphProperty { get; } =
DependencyProperty.Register(nameof(Glyph), typeof(string), typeof(FontIconSource), new FrameworkPropertyMetadata(string.Empty, OnPropertyChanged));
public FontWeight FontWeight
{
get => (FontWeight)GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
public FontWeight FontWeight
{
get => (FontWeight)GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
public static DependencyProperty FontWeightProperty { get; } =
DependencyProperty.Register(nameof(FontWeight), typeof(FontWeight), typeof(FontIconSource), new FrameworkPropertyMetadata(new FontWeight(400), OnPropertyChanged));
public static DependencyProperty FontWeightProperty { get; } =
DependencyProperty.Register(nameof(FontWeight), typeof(FontWeight), typeof(FontIconSource), new FrameworkPropertyMetadata(new FontWeight(400), OnPropertyChanged));
public FontStyle FontStyle
{
get => (FontStyle)GetValue(FontStyleProperty);
set => SetValue(FontStyleProperty, value);
}
public FontStyle FontStyle
{
get => (FontStyle)GetValue(FontStyleProperty);
set => SetValue(FontStyleProperty, value);
}
public static DependencyProperty FontStyleProperty { get; } =
DependencyProperty.Register(nameof(FontStyle), typeof(FontStyle), typeof(FontIconSource), new FrameworkPropertyMetadata(FontStyle.Normal, OnPropertyChanged));
public static DependencyProperty FontStyleProperty { get; } =
DependencyProperty.Register(nameof(FontStyle), typeof(FontStyle), typeof(FontIconSource), new FrameworkPropertyMetadata(FontStyle.Normal, OnPropertyChanged));
public double FontSize
{
get => (double)GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
}
public double FontSize
public static DependencyProperty FontSizeProperty { get; } =
DependencyProperty.Register(nameof(FontSize), typeof(double), typeof(FontIconSource), new FrameworkPropertyMetadata(20.0, OnPropertyChanged));
public FontFamily FontFamily
{
get => (FontFamily)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}
public static DependencyProperty FontFamilyProperty { get; } =
DependencyProperty.Register(nameof(FontFamily), typeof(FontFamily), typeof(FontIconSource), new FrameworkPropertyMetadata(new FontFamily(Uno.UI.FeatureConfiguration.Font.SymbolsFont), OnPropertyChanged));
/// <inheritdoc />
private protected override IconElement CreateIconElementCore()
{
var fontIcon = new FontIcon()
{
get => (double)GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
Glyph = Glyph,
FontSize = FontSize,
FontWeight = FontWeight,
FontStyle = FontStyle,
IsTextScaleFactorEnabled = IsTextScaleFactorEnabled,
MirroredWhenRightToLeft = MirroredWhenRightToLeft,
};
if (FontFamily != null)
{
fontIcon.FontFamily = FontFamily;
}
public static DependencyProperty FontSizeProperty { get; } =
DependencyProperty.Register(nameof(FontSize), typeof(double), typeof(FontIconSource), new FrameworkPropertyMetadata(20.0, OnPropertyChanged));
public FontFamily FontFamily
if (Foreground != null)
{
get => (FontFamily)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
fontIcon.Foreground = Foreground;
}
public static DependencyProperty FontFamilyProperty { get; } =
DependencyProperty.Register(nameof(FontFamily), typeof(FontFamily), typeof(FontIconSource), new FrameworkPropertyMetadata(new FontFamily(Uno.UI.FeatureConfiguration.Font.SymbolsFont), OnPropertyChanged));
return fontIcon;
}
/// <inheritdoc />
private protected override IconElement CreateIconElementCore()
private protected override DependencyProperty GetIconElementPropertyCore(DependencyProperty sourceProperty)
{
if (sourceProperty == FontFamilyProperty)
{
var fontIcon = new FontIcon()
{
Glyph = Glyph,
FontSize = FontSize,
FontWeight = FontWeight,
FontStyle = FontStyle,
IsTextScaleFactorEnabled = IsTextScaleFactorEnabled,
MirroredWhenRightToLeft = MirroredWhenRightToLeft,
};
if (FontFamily != null)
{
fontIcon.FontFamily = FontFamily;
}
if (Foreground != null)
{
fontIcon.Foreground = Foreground;
}
return fontIcon;
return FontIcon.FontFamilyProperty;
}
private protected override DependencyProperty GetIconElementPropertyCore(DependencyProperty sourceProperty)
else if (sourceProperty == FontSizeProperty)
{
if (sourceProperty == FontFamilyProperty)
{
return FontIcon.FontFamilyProperty;
}
else if (sourceProperty == FontSizeProperty)
{
return FontIcon.FontSizeProperty;
}
else if (sourceProperty == FontStyleProperty)
{
return FontIcon.FontStyleProperty;
}
else if (sourceProperty == FontWeightProperty)
{
return FontIcon.FontWeightProperty;
}
else if (sourceProperty == GlyphProperty)
{
return FontIcon.GlyphProperty;
}
else if (sourceProperty == IsTextScaleFactorEnabledProperty)
{
return FontIcon.IsTextScaleFactorEnabledProperty;
}
else if (sourceProperty == MirroredWhenRightToLeftProperty)
{
return FontIcon.MirroredWhenRightToLeftProperty;
}
return base.GetIconElementPropertyCore(sourceProperty);
return FontIcon.FontSizeProperty;
}
else if (sourceProperty == FontStyleProperty)
{
return FontIcon.FontStyleProperty;
}
else if (sourceProperty == FontWeightProperty)
{
return FontIcon.FontWeightProperty;
}
else if (sourceProperty == GlyphProperty)
{
return FontIcon.GlyphProperty;
}
else if (sourceProperty == IsTextScaleFactorEnabledProperty)
{
return FontIcon.IsTextScaleFactorEnabledProperty;
}
else if (sourceProperty == MirroredWhenRightToLeftProperty)
{
return FontIcon.MirroredWhenRightToLeftProperty;
}
return base.GetIconElementPropertyCore(sourceProperty);
}
}
......@@ -10,68 +10,67 @@ using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
namespace Microsoft.UI.Xaml.Controls
namespace Microsoft.UI.Xaml.Controls;
public partial class IconSource : DependencyObject
{
public partial class IconSource : DependencyObject
{
private List<WeakReference<IconElement>> m_createdIconElements = new List<WeakReference<IconElement>>();
private List<WeakReference<IconElement>> m_createdIconElements = new List<WeakReference<IconElement>>();
protected IconSource()
{
}
protected IconSource()
{
}
public Brush Foreground
{
get => (Brush)GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
public Brush Foreground
{
get => (Brush)GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
public static DependencyProperty ForegroundProperty { get; } =
DependencyProperty.Register(nameof(Foreground), typeof(Brush), typeof(IconSource), new FrameworkPropertyMetadata(null, OnPropertyChanged));
public static DependencyProperty ForegroundProperty { get; } =
DependencyProperty.Register(nameof(Foreground), typeof(Brush), typeof(IconSource), new FrameworkPropertyMetadata(null, OnPropertyChanged));
public IconElement? CreateIconElement()
public IconElement? CreateIconElement()
{
var element = CreateIconElementCore();
if (element != null)
{
var element = CreateIconElementCore();
if (element != null)
{
m_createdIconElements.Add(new WeakReference<IconElement>(element));
}
return element;
m_createdIconElements.Add(new WeakReference<IconElement>(element));
}
return element;
}
internal static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
var iconSource = sender as IconSource;
iconSource?.OnPropertyChanged(args);
}
internal static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
var iconSource = sender as IconSource;
iconSource?.OnPropertyChanged(args);
}
private void OnPropertyChanged(DependencyPropertyChangedEventArgs args)
private void OnPropertyChanged(DependencyPropertyChangedEventArgs args)
{
if (GetIconElementPropertyCore(args.Property) is { } iconProp)
{
if (GetIconElementPropertyCore(args.Property) is { } iconProp)
{
m_createdIconElements.RemoveAll(
weakElement =>
m_createdIconElements.RemoveAll(
weakElement =>
{
if (weakElement.TryGetTarget(out var target))
{
if (weakElement.TryGetTarget(out var target))
{
target.SetValue(iconProp, args.NewValue);
return false;
}
return true;
});
}
target.SetValue(iconProp, args.NewValue);
return false;
}
return true;
});
}
}
private protected virtual IconElement? CreateIconElementCore() => default;
private protected virtual IconElement? CreateIconElementCore() => default;
private protected virtual DependencyProperty? GetIconElementPropertyCore(DependencyProperty sourceProperty)
private protected virtual DependencyProperty? GetIconElementPropertyCore(DependencyProperty sourceProperty)
{
if (sourceProperty == ForegroundProperty)
{
if (sourceProperty == ForegroundProperty)
{
return IconElement.ForegroundProperty;
}
return null;
return IconElement.ForegroundProperty;
}
return null;
}
}
......@@ -6,41 +6,40 @@ using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
namespace Microsoft.UI.Xaml.Controls
namespace Microsoft.UI.Xaml.Controls;
public partial class ImageIconSource : IconSource
{
public partial class ImageIconSource : IconSource
public ImageSource ImageSource
{
public ImageSource ImageSource
{
get => (ImageSource)GetValue(ImageSourceProperty);
set => SetValue(ImageSourceProperty, value);
}
get => (ImageSource)GetValue(ImageSourceProperty);
set => SetValue(ImageSourceProperty, value);
}
public static DependencyProperty ImageSourceProperty { get; } =
DependencyProperty.Register(nameof(ImageSource), typeof(ImageSource), typeof(ImageIconSource), new FrameworkPropertyMetadata(null, OnPropertyChanged));
public static DependencyProperty ImageSourceProperty { get; } =
DependencyProperty.Register(nameof(ImageSource), typeof(ImageSource), typeof(ImageIconSource), new FrameworkPropertyMetadata(null, OnPropertyChanged));
private protected override IconElement CreateIconElementCore()
private protected override IconElement CreateIconElementCore()
{
var imageIcon = new ImageIcon();
if (ImageSource is { } imageSource)
{
var imageIcon = new ImageIcon();
if (ImageSource is { } imageSource)
{
imageIcon.Source = imageSource;
}
if (Foreground is { } newForeground)
{
imageIcon.Foreground = newForeground;
}
return imageIcon;
imageIcon.Source = imageSource;
}
private protected override DependencyProperty GetIconElementPropertyCore(DependencyProperty sourceProperty)
if (Foreground is { } newForeground)
{
if (sourceProperty == ImageSourceProperty)
{
return ImageIcon.SourceProperty;
}
imageIcon.Foreground = newForeground;
}
return imageIcon;
}
return base.GetIconElementPropertyCore(sourceProperty);
private protected override DependencyProperty GetIconElementPropertyCore(DependencyProperty sourceProperty)
{
if (sourceProperty == ImageSourceProperty)
{
return ImageIcon.SourceProperty;
}
return base.GetIconElementPropertyCore(sourceProperty);
}
}
......@@ -6,44 +6,43 @@ using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Controls;
namespace Microsoft.UI.Xaml.Controls
namespace Microsoft.UI.Xaml.Controls;
public partial class PathIconSource : IconSource
{
public partial class PathIconSource : IconSource
public Geometry Data
{
public Geometry Data
{
get => (Geometry)GetValue(DataProperty);
set => SetValue(DataProperty, value);
}
public static DependencyProperty DataProperty { get; } =
DependencyProperty.Register(nameof(Data), typeof(Geometry), typeof(PathIconSource), new FrameworkPropertyMetadata(null, OnPropertyChanged));
private protected override IconElement CreateIconElementCore()
{
var pathIcon = new PathIcon();
get => (Geometry)GetValue(DataProperty);
set => SetValue(DataProperty, value);
}
if (Data != null)
{
pathIcon.Data = Data;
}
public static DependencyProperty DataProperty { get; } =
DependencyProperty.Register(nameof(Data), typeof(Geometry), typeof(PathIconSource), new FrameworkPropertyMetadata(null, OnPropertyChanged));
if (Foreground != null)
{
pathIcon.Foreground = Foreground;
}
private protected override IconElement CreateIconElementCore()
{
var pathIcon = new PathIcon();
return pathIcon;
if (Data != null)
{
pathIcon.Data = Data;
}
private protected override DependencyProperty GetIconElementPropertyCore(DependencyProperty sourceProperty)
if (Foreground != null)
{
if (sourceProperty == DataProperty)
{
return PathIcon.DataProperty;
}
pathIcon.Foreground = Foreground;
}
return pathIcon;
}
return base.GetIconElementPropertyCore(sourceProperty);
private protected override DependencyProperty GetIconElementPropertyCore(DependencyProperty sourceProperty)
{
if (sourceProperty == DataProperty)
{
return PathIcon.DataProperty;
}
return base.GetIconElementPropertyCore(sourceProperty);
}
}
......@@ -5,42 +5,41 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.UI.Xaml.Controls
namespace Microsoft.UI.Xaml.Controls;
public partial class SymbolIconSource : IconSource
{
public partial class SymbolIconSource : IconSource
public Symbol Symbol
{
public Symbol Symbol
{
get => (Symbol)GetValue(SymbolProperty);
set => SetValue(SymbolProperty, value);
}
get => (Symbol)GetValue(SymbolProperty);
set => SetValue(SymbolProperty, value);
}
public static DependencyProperty SymbolProperty { get; } =
DependencyProperty.Register(nameof(Symbol), typeof(Symbol), typeof(SymbolIconSource), new FrameworkPropertyMetadata(Symbol.Emoji, OnPropertyChanged));
public static DependencyProperty SymbolProperty { get; } =
DependencyProperty.Register(nameof(Symbol), typeof(Symbol), typeof(SymbolIconSource), new FrameworkPropertyMetadata(Symbol.Emoji, OnPropertyChanged));
private protected override IconElement CreateIconElementCore()
private protected override IconElement CreateIconElementCore()
{
var symbolIcon = new SymbolIcon()
{
var symbolIcon = new SymbolIcon()
{
Symbol = Symbol
};
if (Foreground != null)
{
symbolIcon.Foreground = Foreground;
}
Symbol = Symbol
};
return symbolIcon;
if (Foreground != null)
{
symbolIcon.Foreground = Foreground;
}
private protected override DependencyProperty GetIconElementPropertyCore(DependencyProperty sourceProperty)
{
if (sourceProperty == SymbolProperty)
{
return SymbolIcon.SymbolProperty;
}
return symbolIcon;
}
return base.GetIconElementPropertyCore(sourceProperty);
private protected override DependencyProperty GetIconElementPropertyCore(DependencyProperty sourceProperty)
{
if (sourceProperty == SymbolProperty)
{
return SymbolIcon.SymbolProperty;
}
return base.GetIconElementPropertyCore(sourceProperty);
}
}
......@@ -30,10 +30,7 @@ namespace Microsoft.UI.Xaml.Controls
Stretch = Stretch.Uniform
};
var grid = new Grid();
grid.Children.Add(image);
AddIconElementView(grid);
AddIconChild(image);
_initialized = true;
}
}
......
using System;
using System.Collections.Generic;
using System.Text;
using Windows.Foundation;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
namespace Windows.UI.Xaml.Controls
{
public partial class BitmapIcon : IconElement
{
private Image _image;
private Grid _grid;
public BitmapIcon()
{
this.SetValue(ForegroundProperty, SolidColorBrushHelper.Black, DependencyPropertyValuePrecedences.Inheritance);
}
protected override Size MeasureOverride(Size availableSize)
{
if (_image == null)
{
_image = new Image
{
Stretch = Media.Stretch.Uniform
};
UpdateImageMonochromeColor();
_image.SetBinding(
dependencyProperty: Image.SourceProperty,
binding: new Binding { Source = this, Path = nameof(UriSource) }
);
_grid = new Grid();
_grid.Children.Add(_image);
AddIconElementView(_grid);
}
return base.MeasureOverride(availableSize);
}
public bool ShowAsMonochrome
{
get => (bool)GetValue(ShowAsMonochromeProperty);
set => SetValue(ShowAsMonochromeProperty, value);
}
public static global::Windows.UI.Xaml.DependencyProperty ShowAsMonochromeProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
"ShowAsMonochrome", typeof(bool),
typeof(global::Windows.UI.Xaml.Controls.BitmapIcon),
new FrameworkPropertyMetadata(true, (s, e) => (s as BitmapIcon)?.OnShowAsMonochromeChanged((bool)e.NewValue)));
private void OnShowAsMonochromeChanged(bool value) => UpdateImageMonochromeColor();
protected override void OnForegroundChanged(DependencyPropertyChangedEventArgs e)
{
base.OnForegroundChanged(e);
UpdateImageMonochromeColor();
}
private void UpdateImageMonochromeColor()
{
#if !NET461
if (_image != null)
{
_image.MonochromeColor = ShowAsMonochrome ? (Foreground as SolidColorBrush)?.Color : null;
}
#endif
}
public Uri UriSource
{
get => (Uri)GetValue(UriSourceProperty);
set => SetValue(UriSourceProperty, value);
}
public static DependencyProperty UriSourceProperty { get; } =
DependencyProperty.Register(
"UriSource",
typeof(Uri),
typeof(BitmapIcon),
new FrameworkPropertyMetadata(default(Uri))
);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Uno;
using Windows.UI.Text;
using Windows.UI.Xaml.Media;
namespace Windows.UI.Xaml.Controls
{
public partial class FontIcon : IconElement
{
private readonly TextBlock _textBlock;
public FontIcon()
{
_textBlock = new TextBlock();
AddIconElementView(_textBlock);
Loaded += FontIcon_Loaded;
}
private void FontIcon_Loaded(object sender, RoutedEventArgs e)
{
SynchronizeProperties();
}
private void SynchronizeProperties()
{
_textBlock.Text = Glyph;
_textBlock.FontSize = FontSize;
_textBlock.FontStyle = FontStyle;
_textBlock.FontFamily = FontFamily;
_textBlock.Foreground = Foreground;
_textBlock.VerticalAlignment = VerticalAlignment.Center;
_textBlock.HorizontalAlignment = HorizontalAlignment.Center;
_textBlock.TextAlignment = Windows.UI.Xaml.TextAlignment.Center;
}
#region Glyph
public string Glyph
{
get => (string)GetValue(GlyphProperty);
set => SetValue(GlyphProperty, value);
}
public static DependencyProperty GlyphProperty { get; } =
DependencyProperty.Register(
nameof(Glyph),
typeof(string),
typeof(FontIcon),
new FrameworkPropertyMetadata(
string.Empty,
(s, e) => ((FontIcon)s).OnGlyphChanged((string)e.NewValue)));
private void OnGlyphChanged(string newValue)
{
if (_textBlock != null)
{
_textBlock.Text = newValue;
}
}
#endregion
#region FontFamily
public FontFamily FontFamily
{
get { return (FontFamily)this.GetValue(FontFamilyProperty); }
set { this.SetValue(FontFamilyProperty, value); }
}
public static DependencyProperty FontFamilyProperty { get; } =
DependencyProperty.Register(
name: nameof(FontFamily),
propertyType: typeof(FontFamily),
ownerType: typeof(FontIcon),
typeMetadata: new FrameworkPropertyMetadata(
defaultValue: new FontFamily(Uno.UI.FeatureConfiguration.Font.SymbolsFont),
propertyChangedCallback: (s, e) => ((FontIcon)s).OnFontFamilyChanged((FontFamily)e.NewValue)
)
);
private void OnFontFamilyChanged(FontFamily newValue)
{
if (_textBlock != null)
{
_textBlock.FontFamily = newValue;
}
}
#endregion
#region FontStyle
public FontStyle FontStyle
{
get { return (FontStyle)GetValue(FontStyleProperty); }
set { SetValue(FontStyleProperty, value); }
}
public static DependencyProperty FontStyleProperty { get; } =
DependencyProperty.Register("FontStyle", typeof(FontStyle), typeof(FontIcon), new FrameworkPropertyMetadata(FontStyle.Normal,
(s, e) => ((FontIcon)s).OnFontStyleChanged((FontStyle)e.NewValue)));
private void OnFontStyleChanged(FontStyle newValue)
{
if (_textBlock != null)
{
_textBlock.FontStyle = newValue;
}
}
#endregion
#region FontSize
public double FontSize
{
get => (double)GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
}
public static DependencyProperty FontSizeProperty { get; } =
DependencyProperty.Register(
nameof(FontSize),
typeof(double),
typeof(FontIcon),
new FrameworkPropertyMetadata(
20.0,
(s, e) => ((FontIcon)s).OnFontSizeChanged((double)e.NewValue)));
private void OnFontSizeChanged(double newValue)
{
if (_textBlock != null)
{
_textBlock.FontSize = newValue;
}
}
#endregion
#region FontWeight
public FontWeight FontWeight
{
get => (FontWeight)GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
public static DependencyProperty FontWeightProperty { get; } =
DependencyProperty.Register(
nameof(FontWeight),
typeof(FontWeight),
typeof(FontIcon),
new FrameworkPropertyMetadata(
new FontWeight(400),
(s, e) => ((FontIcon)s).OnFontWeightChanged((FontWeight)e.NewValue)));
private void OnFontWeightChanged(FontWeight newValue)
{
if (_textBlock != null)
{
_textBlock.FontWeight = newValue;
}
}
#endregion
#region IsTextScaleFactorEnabled
[NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public bool IsTextScaleFactorEnabled
{
get => (bool)this.GetValue(IsTextScaleFactorEnabledProperty);
set => SetValue(IsTextScaleFactorEnabledProperty, value);
}
[NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static DependencyProperty IsTextScaleFactorEnabledProperty { get; } =
DependencyProperty.Register(
nameof(IsTextScaleFactorEnabled),
typeof(bool),
typeof(FontIcon),
new FrameworkPropertyMetadata(true));
#endregion
protected override void OnForegroundChanged(DependencyPropertyChangedEventArgs e)
{
if (_textBlock != null)
{
_textBlock.Foreground = e.NewValue as Brush;
}
}
}
}
using System;
using Windows.Foundation.Metadata;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Windows.UI.Xaml.Controls
{
public partial class BitmapIconSource : IconSource
{
public BitmapIconSource()
{
}
public Uri UriSource
{
get => (Uri)GetValue(UriSourceProperty);
set => SetValue(UriSourceProperty, value);
}
public static DependencyProperty UriSourceProperty { get; } =
DependencyProperty.Register(nameof(UriSource), typeof(Uri), typeof(BitmapIconSource), new FrameworkPropertyMetadata(default(Uri)));
public bool ShowAsMonochrome
{
get => (bool)GetValue(ShowAsMonochromeProperty);
set => SetValue(ShowAsMonochromeProperty, value);
}
public static DependencyProperty ShowAsMonochromeProperty { get; } =
DependencyProperty.Register(nameof(ShowAsMonochrome), typeof(bool), typeof(BitmapIconSource), new FrameworkPropertyMetadata(true));
public override IconElement CreateIconElement()
{
var bitmapIcon = new BitmapIcon();
if (UriSource != null)
{
bitmapIcon.UriSource = UriSource;
}
if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.BitmapIcon", "ShowAsMonochrome"))
{
bitmapIcon.ShowAsMonochrome = ShowAsMonochrome;
}
if (Foreground != null)
{
bitmapIcon.Foreground = Foreground;
}
return bitmapIcon;
}
}
}
using Windows.UI.Text;
using Windows.UI.Xaml.Media;
namespace Windows.UI.Xaml.Controls
{
public partial class FontIconSource : global::Windows.UI.Xaml.Controls.IconSource
{
public bool MirroredWhenRightToLeft
{
get => (bool)GetValue(MirroredWhenRightToLeftProperty);
set => SetValue(MirroredWhenRightToLeftProperty, value);
}
public static DependencyProperty MirroredWhenRightToLeftProperty { get; } =
DependencyProperty.Register(nameof(MirroredWhenRightToLeft), typeof(bool), typeof(FontIconSource), new FrameworkPropertyMetadata(false));
public bool IsTextScaleFactorEnabled
{
get => (bool)GetValue(IsTextScaleFactorEnabledProperty);
set => SetValue(IsTextScaleFactorEnabledProperty, value);
}
public static DependencyProperty IsTextScaleFactorEnabledProperty { get; } =
DependencyProperty.Register(nameof(IsTextScaleFactorEnabled), typeof(bool), typeof(FontIconSource), new FrameworkPropertyMetadata(true));
public string Glyph
{
get => (string)GetValue(GlyphProperty);
set => SetValue(GlyphProperty, value);
}
public static DependencyProperty GlyphProperty { get; } =
DependencyProperty.Register(nameof(Glyph), typeof(string), typeof(FontIconSource), new FrameworkPropertyMetadata(string.Empty));
public FontWeight FontWeight
{
get => (FontWeight)GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
public static DependencyProperty FontWeightProperty { get; } =
DependencyProperty.Register(nameof(FontWeight), typeof(FontWeight), typeof(FontIconSource), new FrameworkPropertyMetadata(new FontWeight(400)));
public FontStyle FontStyle
{
get => (FontStyle)GetValue(FontStyleProperty);
set => SetValue(FontStyleProperty, value);
}
public static DependencyProperty FontStyleProperty { get; } =
DependencyProperty.Register(nameof(FontStyle), typeof(FontStyle), typeof(FontIconSource), new FrameworkPropertyMetadata(FontStyle.Normal));
public double FontSize
{
get => (double)GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
}
public static DependencyProperty FontSizeProperty { get; } =
DependencyProperty.Register(nameof(FontSize), typeof(double), typeof(FontIconSource), new FrameworkPropertyMetadata(20.0));
public FontFamily FontFamily
{
get => (FontFamily)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}
public static DependencyProperty FontFamilyProperty { get; } =
DependencyProperty.Register(nameof(FontFamily), typeof(FontFamily), typeof(FontIconSource), new FrameworkPropertyMetadata(new FontFamily(Uno.UI.FeatureConfiguration.Font.SymbolsFont)));
/// <inheritdoc />
public override IconElement CreateIconElement()
{
var fontIcon = new FontIcon()
{
Glyph = Glyph,
FontSize = FontSize,
FontWeight = FontWeight,
FontStyle = FontStyle,
IsTextScaleFactorEnabled = IsTextScaleFactorEnabled,
MirroredWhenRightToLeft = MirroredWhenRightToLeft,
};
if (FontFamily != null)
{
fontIcon.FontFamily = FontFamily;
}
if (Foreground != null)
{
fontIcon.Foreground = Foreground;
}
return fontIcon;
}
}
}
using Windows.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.Text;
using UIKit;
namespace Windows.UI.Xaml.Controls
{
public partial class IconElement
{
partial void RegisterSubView(UIView child)
{
if (Subviews.Length != 0)
{
throw new InvalidOperationException("A Xaml IconElement may not contain more than one child.");
}
child.Frame = Bounds;
child.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
AddSubview(child);
}
}
}
using System;
using AppKit;
namespace Windows.UI.Xaml.Controls
{
public partial class IconElement
{
partial void RegisterSubView(NSView child)
{
if (Subviews.Length != 0)
{
throw new Exception("A Xaml IconElement may not contain more than one child.");
}
child.Frame = Bounds;
child.AutoresizingMask = NSViewResizingMask.HeightSizable | NSViewResizingMask.WidthSizable;
AddSubview(child);
}
}
}
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml;
using System;
using System.Collections.Generic;
using System.Text;
namespace Windows.UI.Xaml.Controls
{
public partial class IconElement
{
partial void RegisterSubView(UIElement child)
{
AddChild(child);
}
}
}
using Windows.UI.Xaml.Media;
namespace Windows.UI.Xaml.Controls
{
public partial class IconSource : DependencyObject
{
protected IconSource()
{
}
public Brush Foreground
{
get => (Brush)GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
public static DependencyProperty ForegroundProperty { get; } =
DependencyProperty.Register(nameof(Foreground), typeof(Brush), typeof(IconSource), new FrameworkPropertyMetadata(null));
#nullable enable
public virtual IconElement? CreateIconElement() => default;
}
}
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Controls;
namespace Windows.UI.Xaml.Controls
{
public partial class PathIconSource : IconSource
{
public PathIconSource()
{
}
public Geometry Data
{
get => (Geometry)GetValue(DataProperty);
set => SetValue(DataProperty, value);
}
public static DependencyProperty DataProperty { get; } =
DependencyProperty.Register(nameof(Data), typeof(Geometry), typeof(PathIconSource), new FrameworkPropertyMetadata(null));
public override IconElement CreateIconElement()
{
var pathIcon = new PathIcon();
if (Data != null)
{
pathIcon.Data = Data;
}
if (Foreground != null)
{
pathIcon.Foreground = Foreground;
}
return pathIcon;
}
}
}
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Windows.UI.Xaml.Controls
{
public partial class SymbolIconSource : IconSource
{
public SymbolIconSource()
{
}
public Symbol Symbol
{
get => (Symbol)GetValue(SymbolProperty);
set => SetValue(SymbolProperty, value);
}
public static DependencyProperty SymbolProperty { get; } =
DependencyProperty.Register(nameof(Symbol), typeof(Symbol), typeof(SymbolIconSource), new FrameworkPropertyMetadata(Symbol.Emoji));
public override IconElement CreateIconElement()
{
var symbolIcon = new SymbolIcon()
{
Symbol = Symbol
};
if (Foreground != null)
{
symbolIcon.Foreground = Foreground;
}
return symbolIcon;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Uno.Extensions;
using Uno;
using Uno.UI.DataBinding;
using System.Linq;
using Windows.UI.Xaml.Shapes;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Controls;
using System.ComponentModel;
#if XAMARIN_ANDROID
using View = Android.Views.View;
using ViewGroup = Android.Views.ViewGroup;
using Font = Android.Graphics.Typeface;
using Android.Graphics;
#elif XAMARIN_IOS_UNIFIED
using View = UIKit.UIView;
using ViewGroup = UIKit.UIView;
using Color = UIKit.UIColor;
using Font = UIKit.UIFont;
#elif XAMARIN_IOS
using View = MonoTouch.UIKit.UIView;
using ViewGroup = MonoTouch.UIKit.UIView;
using Color = MonoTouch.UIKit.UIColor;
using Font = MonoTouch.UIKit.UIFont;
#elif __MACOS__
using View = AppKit.NSView;
#else
using View = Windows.UI.Xaml.UIElement;
#endif
namespace Windows.UI.Xaml.Controls
{
public partial class IconElement : FrameworkElement
{
#if false
partial void UnregisterSubView();
#endif
partial void RegisterSubView(View child);
//This field is never accessed. It just exists to create a reference, because the DP causes issues with ImageBrush of the backing bitmap being prematurely garbage-collected. (Bug with ConditionalWeakTable? https://bugzilla.xamarin.com/show_bug.cgi?id=21620)
private Brush _foregroundStrongref;
public IconElement()
{
}
public
#if __ANDROID_23__
new
#endif
Brush Foreground
{
get { return (Brush)this.GetValue(ForegroundProperty); }
set
{
this.SetValue(ForegroundProperty, value);
_foregroundStrongref = value;
}
}
public static DependencyProperty ForegroundProperty { get; } =
DependencyProperty.Register(
"Foreground",
typeof(Brush),
typeof(IconElement),
new FrameworkPropertyMetadata(
SolidColorBrushHelper.White,
FrameworkPropertyMetadataOptions.Inherits,
propertyChangedCallback: (s, e) => ((IconElement)s).OnForegroundChanged(e)
)
);
protected virtual void OnForegroundChanged(DependencyPropertyChangedEventArgs e) { }
internal void AddIconElementView(View child)
{
RegisterSubView(child);
}
public static implicit operator IconElement(string symbol)
{
return new SymbolIcon() { Symbol = (Symbol)Enum.Parse(typeof(Symbol), symbol, true) };
}
internal override bool CanHaveChildren() => true;
}
}
using System;
using Windows.Foundation;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
namespace Windows.UI.Xaml.Controls;
/// <summary>
/// Represents an icon that uses a bitmap as its content.
/// </summary>
public partial class BitmapIcon : IconElement
{
private readonly Image _image;
/// <summary>
/// Initializes a new instance of the BitmapIcon class.
/// </summary>
public BitmapIcon()
{
_image = new Image();
AddIconChild(_image);
_image.SetBinding(
dependencyProperty: Image.SourceProperty,
binding: new Binding { Source = this, Path = nameof(UriSource) }
);
this.SetValue(ForegroundProperty, SolidColorBrushHelper.Black, DependencyPropertyValuePrecedences.Inheritance);
UpdateImageMonochromeColor();
}
/// <summary>
/// Gets or sets a value that indicates whether the bitmap is shown in a single color.
/// </summary>
public bool ShowAsMonochrome
{
get => (bool)GetValue(ShowAsMonochromeProperty);
set => SetValue(ShowAsMonochromeProperty, value);
}
/// <summary>
/// Identifies the ShowAsMonochrome dependency property.
/// </summary>
public static DependencyProperty ShowAsMonochromeProperty { get; } =
DependencyProperty.Register(
nameof(ShowAsMonochrome), typeof(bool),
typeof(BitmapIcon),
new FrameworkPropertyMetadata(true, (s, e) => (s as BitmapIcon)?.OnShowAsMonochromeChanged((bool)e.NewValue)));
/// <summary>
/// Gets or sets the Uniform Resource Identifier (URI) of the graphics source file that generated this BitmapImage.
/// </summary>
public Uri UriSource
{
get => (Uri)GetValue(UriSourceProperty);
set => SetValue(UriSourceProperty, value);
}
/// <summary>
/// Identifies the UriSource dependency property.
/// </summary>
public static DependencyProperty UriSourceProperty { get; } =
DependencyProperty.Register(
nameof(UriSource),
typeof(Uri),
typeof(BitmapIcon),
new FrameworkPropertyMetadata(default(Uri)));
private void OnShowAsMonochromeChanged(bool value) => UpdateImageMonochromeColor();
private protected override void OnForegroundChanged(DependencyPropertyChangedEventArgs e) =>
UpdateImageMonochromeColor();
private void UpdateImageMonochromeColor()
{
#if !NET461
if (_image != null)
{
_image.MonochromeColor = ShowAsMonochrome ? (Foreground as SolidColorBrush)?.Color : null;
}
#endif
}
}
using System;
using Windows.Foundation.Metadata;
namespace Windows.UI.Xaml.Controls;
public partial class BitmapIconSource : IconSource
{
public BitmapIconSource()
{
}
public Uri UriSource
{
get => (Uri)GetValue(UriSourceProperty);
set => SetValue(UriSourceProperty, value);
}
public static DependencyProperty UriSourceProperty { get; } =
DependencyProperty.Register(nameof(UriSource), typeof(Uri), typeof(BitmapIconSource), new FrameworkPropertyMetadata(default(Uri)));
public bool ShowAsMonochrome
{
get => (bool)GetValue(ShowAsMonochromeProperty);
set => SetValue(ShowAsMonochromeProperty, value);
}
public static DependencyProperty ShowAsMonochromeProperty { get; } =
DependencyProperty.Register(nameof(ShowAsMonochrome), typeof(bool), typeof(BitmapIconSource), new FrameworkPropertyMetadata(true));
public override IconElement CreateIconElement()
{
var bitmapIcon = new BitmapIcon();
if (UriSource != null)
{
bitmapIcon.UriSource = UriSource;
}
if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.BitmapIcon", "ShowAsMonochrome"))
{
bitmapIcon.ShowAsMonochrome = ShowAsMonochrome;
}
if (Foreground != null)
{
bitmapIcon.Foreground = Foreground;
}
return bitmapIcon;
}
}
#nullable enable
using Uno;
using Windows.Foundation;
using Windows.UI.Text;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Automation;
using Windows.UI.Xaml.Automation.Peers;
namespace Windows.UI.Xaml.Controls;
/// <summary>
/// Represents an icon that uses a glyph from the specified font.
/// </summary>
public partial class FontIcon : IconElement
{
private readonly TextBlock _textBlock;
private ScaleTransform? _scaleTransform;
/// <summary>
/// Initializes a new instance of the FontIcon class.
/// </summary>
public FontIcon()
{
_textBlock = new TextBlock();
AddIconChild(_textBlock);
SynchronizeProperties();
}
/// <summary>
/// Gets or sets the font used to display the icon glyph.
/// </summary>
public FontFamily FontFamily
{
get => (FontFamily)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}
/// <summary>
/// Gets the identifier for the FontFamily dependency property.
/// </summary>
public static DependencyProperty FontFamilyProperty { get; } =
DependencyProperty.Register(
nameof(FontFamily),
typeof(FontFamily),
typeof(FontIcon),
new FrameworkPropertyMetadata(
new FontFamily(Uno.UI.FeatureConfiguration.Font.SymbolsFont),
(s, e) => ((FontIcon)s)._textBlock.FontFamily = (FontFamily)e.NewValue));
/// <summary>
/// Gets or sets the size of the icon glyph.
/// </summary>
public double FontSize
{
get => (double)GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
}
/// <summary>
/// Gets the identifier for the FontSize dependency property.
/// </summary>
public static DependencyProperty FontSizeProperty { get; } =
DependencyProperty.Register(
nameof(FontSize),
typeof(double),
typeof(FontIcon),
new FrameworkPropertyMetadata(
20.0,
(s, e) => ((FontIcon)s)._textBlock.FontSize = (double)e.NewValue));
/// <summary>
/// Gets or sets the font style for the icon glyph.
/// </summary>
public FontStyle FontStyle
{
get => (FontStyle)GetValue(FontStyleProperty);
set => SetValue(FontStyleProperty, value);
}
/// <summary>
/// Gets the identifier for the FontStyle dependency property.
/// </summary>
public static DependencyProperty FontStyleProperty { get; } =
DependencyProperty.Register(
nameof(FontStyle),
typeof(FontStyle),
typeof(FontIcon),
new FrameworkPropertyMetadata(
FontStyle.Normal,
(s, e) => ((FontIcon)s)._textBlock.FontStyle = (FontStyle)e.NewValue));
/// <summary>
/// Gets or sets the thickness of the icon glyph.
/// </summary>
public FontWeight FontWeight
{
get => (FontWeight)GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
/// <summary>
/// Gets the identifier for the FontWeight dependency property.
/// </summary>
public static DependencyProperty FontWeightProperty { get; } =
DependencyProperty.Register(
nameof(FontWeight),
typeof(FontWeight),
typeof(FontIcon),
new FrameworkPropertyMetadata(
new FontWeight(400),
(s, e) => ((FontIcon)s)._textBlock.FontWeight = (FontWeight)e.NewValue));
/// <summary>
/// Gets or sets the font used to display the icon glyph.
/// </summary>
public string Glyph
{
get => (string)GetValue(GlyphProperty);
set => SetValue(GlyphProperty, value);
}
/// <summary>
/// Gets the identifier for the FontFamily dependency property.
/// </summary>
public static DependencyProperty GlyphProperty { get; } =
DependencyProperty.Register(
nameof(Glyph),
typeof(string),
typeof(FontIcon),
new FrameworkPropertyMetadata(
string.Empty,
(s, e) => ((FontIcon)s)._textBlock.Text = (string)e.NewValue));
/// <summary>
/// Gets or sets whether automatic text enlargement, to reflect the system text size setting, is enabled.
/// </summary>
[NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public bool IsTextScaleFactorEnabled
{
get => (bool)this.GetValue(IsTextScaleFactorEnabledProperty);
set => SetValue(IsTextScaleFactorEnabledProperty, value);
}
/// <summary>
/// Identifies the IsTextScaleFactorEnabled dependency property.
/// </summary>
[NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static DependencyProperty IsTextScaleFactorEnabledProperty { get; } =
DependencyProperty.Register(
nameof(IsTextScaleFactorEnabled),
typeof(bool),
typeof(FontIcon),
new FrameworkPropertyMetadata(
true,
(s, e) => ((FontIcon)s)._textBlock.IsTextScaleFactorEnabled = (bool)e.NewValue));
/// <summary>
/// Gets or sets a value that indicates whether the icon is mirrored when the FlowDirection is RightToLeft.
/// </summary>
public bool MirroredWhenRightToLeft
{
get => (bool)GetValue(MirroredWhenRightToLeftProperty);
set => SetValue(MirroredWhenRightToLeftProperty, value);
}
/// <summary>
/// Identifies the MirroredWhenRightToLeft dependency property.
/// </summary>
public static DependencyProperty MirroredWhenRightToLeftProperty { get; } =
DependencyProperty.Register(
nameof(MirroredWhenRightToLeft),
typeof(bool),
typeof(FontIcon),
new FrameworkPropertyMetadata(
false,
propertyChangedCallback: (s, e) => ((FontIcon)s).UpdateMirroring()));
private void SynchronizeProperties()
{
_textBlock.Style = null;
_textBlock.VerticalAlignment = VerticalAlignment.Center;
_textBlock.HorizontalAlignment = HorizontalAlignment.Center;
_textBlock.TextAlignment = Windows.UI.Xaml.TextAlignment.Center;
_textBlock.SetValue(AutomationProperties.AccessibilityViewProperty, AccessibilityView.Raw);
_textBlock.Text = Glyph;
_textBlock.FontSize = FontSize;
_textBlock.FontStyle = FontStyle;
_textBlock.FontFamily = FontFamily;
_textBlock.Foreground = Foreground;
_textBlock.IsTextScaleFactorEnabled = IsTextScaleFactorEnabled;
}
private void UpdateMirroring()
{
if (_scaleTransform is null &&
FlowDirection == FlowDirection.RightToLeft &&
MirroredWhenRightToLeft)
{
_scaleTransform = new ScaleTransform();
RenderTransform = _scaleTransform;
RenderTransformOrigin = new Point(0.5, 0.5);
}
if (_scaleTransform is not null)
{
_scaleTransform.ScaleX = FlowDirection == FlowDirection.RightToLeft && MirroredWhenRightToLeft ? -1 : 1;
}
}
private protected override void OnForegroundChanged(DependencyPropertyChangedEventArgs e) =>
_textBlock.Foreground = (Brush)e.NewValue;
}
using Windows.UI.Text;
using Windows.UI.Xaml.Media;
namespace Windows.UI.Xaml.Controls;
public partial class FontIconSource : global::Windows.UI.Xaml.Controls.IconSource
{
public bool MirroredWhenRightToLeft
{
get => (bool)GetValue(MirroredWhenRightToLeftProperty);
set => SetValue(MirroredWhenRightToLeftProperty, value);
}
public static DependencyProperty MirroredWhenRightToLeftProperty { get; } =
DependencyProperty.Register(nameof(MirroredWhenRightToLeft), typeof(bool), typeof(FontIconSource), new FrameworkPropertyMetadata(false));
public bool IsTextScaleFactorEnabled
{
get => (bool)GetValue(IsTextScaleFactorEnabledProperty);
set => SetValue(IsTextScaleFactorEnabledProperty, value);
}
public static DependencyProperty IsTextScaleFactorEnabledProperty { get; } =
DependencyProperty.Register(nameof(IsTextScaleFactorEnabled), typeof(bool), typeof(FontIconSource), new FrameworkPropertyMetadata(true));
public string Glyph
{
get => (string)GetValue(GlyphProperty);
set => SetValue(GlyphProperty, value);
}
public static DependencyProperty GlyphProperty { get; } =
DependencyProperty.Register(nameof(Glyph), typeof(string), typeof(FontIconSource), new FrameworkPropertyMetadata(string.Empty));
public FontWeight FontWeight
{
get => (FontWeight)GetValue(FontWeightProperty);
set => SetValue(FontWeightProperty, value);
}
public static DependencyProperty FontWeightProperty { get; } =
DependencyProperty.Register(nameof(FontWeight), typeof(FontWeight), typeof(FontIconSource), new FrameworkPropertyMetadata(new FontWeight(400)));
public FontStyle FontStyle
{
get => (FontStyle)GetValue(FontStyleProperty);
set => SetValue(FontStyleProperty, value);
}
public static DependencyProperty FontStyleProperty { get; } =
DependencyProperty.Register(nameof(FontStyle), typeof(FontStyle), typeof(FontIconSource), new FrameworkPropertyMetadata(FontStyle.Normal));
public double FontSize
{
get => (double)GetValue(FontSizeProperty);
set => SetValue(FontSizeProperty, value);
}
public static DependencyProperty FontSizeProperty { get; } =
DependencyProperty.Register(nameof(FontSize), typeof(double), typeof(FontIconSource), new FrameworkPropertyMetadata(20.0));
public FontFamily FontFamily
{
get => (FontFamily)GetValue(FontFamilyProperty);
set => SetValue(FontFamilyProperty, value);
}
public static DependencyProperty FontFamilyProperty { get; } =
DependencyProperty.Register(nameof(FontFamily), typeof(FontFamily), typeof(FontIconSource), new FrameworkPropertyMetadata(new FontFamily(Uno.UI.FeatureConfiguration.Font.SymbolsFont)));
/// <inheritdoc />
public override IconElement CreateIconElement()
{
var fontIcon = new FontIcon()
{
Glyph = Glyph,
FontSize = FontSize,
FontWeight = FontWeight,
FontStyle = FontStyle,
IsTextScaleFactorEnabled = IsTextScaleFactorEnabled,
MirroredWhenRightToLeft = MirroredWhenRightToLeft,
};
if (FontFamily != null)
{
fontIcon.FontFamily = FontFamily;
}
if (Foreground != null)
{
fontIcon.Foreground = Foreground;
}
return fontIcon;
}
}
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using Windows.Foundation;
using Windows.UI.Xaml.Media;
namespace Windows.UI.Xaml.Controls;
/// <summary>
/// Represents the base class for an icon UI element.
/// </summary>
public partial class IconElement : FrameworkElement
{
private Grid? _rootGrid;
//This field is never accessed. It just exists to create a reference, because the DP causes is sues with ImageBrush of the backing bitmap being prematurely garbage-collected. (Bug with ConditionalWeakTable? https://bugzilla.xamarin.com/show_bug.cgi?id=21620)
private Brush? _foregroundStrongref;
public IconElement()
{
}
/// <summary>
/// Gets or sets a brush that describes the foreground color.
/// </summary>
public
#if __ANDROID_23__
new
#endif
Brush Foreground
{
get => (Brush)GetValue(ForegroundProperty);
set
{
SetValue(ForegroundProperty, value);
_foregroundStrongref = value;
}
}
/// <summary>
/// Identifies the Foreground dependency property.
/// </summary>
public static DependencyProperty ForegroundProperty { get; } =
DependencyProperty.Register(
nameof(Foreground),
typeof(Brush),
typeof(IconElement),
new FrameworkPropertyMetadata(
SolidColorBrushHelper.White,
FrameworkPropertyMetadataOptions.Inherits,
propertyChangedCallback: (s, e) => ((IconElement)s).OnForegroundChanged(e)
)
);
public static implicit operator IconElement(string symbol) =>
new SymbolIcon()
{
Symbol = (Symbol)Enum.Parse(typeof(Symbol), symbol, true)
};
protected override Size MeasureOverride(Size availableSize)
{
if (_rootGrid is not null)
{
// Measure the child
_rootGrid.Measure(availableSize);
return _rootGrid.DesiredSize;
}
return default;
}
protected override Size ArrangeOverride(Size finalSize)
{
if (_rootGrid is not null)
{
Rect arrangeRect = new Rect(0, 0, finalSize.Width, finalSize.Height);
_rootGrid.Arrange(arrangeRect);
}
return finalSize;
}
private protected virtual void OnForegroundChanged(DependencyPropertyChangedEventArgs e) { }
[MemberNotNull(nameof(_rootGrid))]
private protected void InitializeRootGrid()
{
if (_rootGrid is not null)
{
return;
}
var backgroundBrush = new SolidColorBrush()
{
Color = Windows.UI.Color.FromArgb(0, 0, 0, 0)
};
_rootGrid = new Grid()
{
Background = backgroundBrush
};
VisualTreeHelper.AddChild(this, _rootGrid);
}
internal void AddIconChild(UIElement child)
{
InitializeRootGrid();
_rootGrid.Children.Add(child);
}
internal void RemoveIconChild()
{
InitializeRootGrid();
_rootGrid.Children.Clear();
}
internal override bool CanHaveChildren() => true;
}
#nullable enable
using Windows.UI.Xaml.Media;
namespace Windows.UI.Xaml.Controls;
public partial class IconSource : DependencyObject
{
protected IconSource()
{
}
public Brush? Foreground
{
get => (Brush?)GetValue(ForegroundProperty);
set => SetValue(ForegroundProperty, value);
}
public static DependencyProperty ForegroundProperty { get; } =
DependencyProperty.Register(nameof(Foreground), typeof(Brush), typeof(IconSource), new FrameworkPropertyMetadata(null));
public virtual IconElement? CreateIconElement() => default;
}
\ No newline at end of file
#nullable enable
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Markup;
namespace Windows.UI.Xaml.Controls;
/// <summary>
/// Represents an icon that uses an IconSource as its content.
/// </summary>
[ContentProperty(Name = nameof(IconSource))]
public partial class IconSourceElement : IconElement
{
private IconElement? _iconElement;
/// <summary>
/// Initializes a new instance of the IconSourceElement class.
/// </summary>
public IconSourceElement()
{
}
/// <summary>
/// Gets or sets the IconSource used as the icon content.
/// </summary>
public IconSource IconSource
{
get => (IconSource)GetValue(IconSourceProperty);
set => SetValue(IconSourceProperty, value);
}
/// <summary>
/// Identifies the IconSource dependency property.
/// </summary>
public static DependencyProperty IconSourceProperty { get; } =
DependencyProperty.Register(
nameof(IconSource),
typeof(IconSource),
typeof(IconSourceElement),
new FrameworkPropertyMetadata(
null,
propertyChangedCallback: (s, e) => ((IconSourceElement)s).UpdateIconElement()));
private void UpdateIconElement()
{
if (_iconElement is not null)
{
RemoveIconChild();
_iconElement = null;
}
if (IconSource is null)
{
return;
}
if (IconSource is FontIconSource fontIconSource)
{
_iconElement = new FontIcon();
SetIconBinding(_iconElement, nameof(fontIconSource.Glyph), FontIcon.GlyphProperty);
SetIconBinding(_iconElement, nameof(fontIconSource.FontFamily), FontIcon.FontFamilyProperty);
SetIconBinding(_iconElement, nameof(fontIconSource.FontSize), FontIcon.FontSizeProperty);
SetIconBinding(_iconElement, nameof(fontIconSource.FontStyle), FontIcon.FontStyleProperty);
SetIconBinding(_iconElement, nameof(fontIconSource.FontWeight), FontIcon.FontWeightProperty);
SetIconBinding(_iconElement, nameof(fontIconSource.IsTextScaleFactorEnabled), FontIcon.IsTextScaleFactorEnabledProperty);
SetIconBinding(_iconElement, nameof(fontIconSource.MirroredWhenRightToLeft), FontIcon.MirroredWhenRightToLeftProperty);
}
else if (IconSource is SymbolIconSource symbolIconSource)
{
_iconElement = new SymbolIcon();
SetIconBinding(_iconElement, nameof(symbolIconSource.Symbol), SymbolIcon.SymbolProperty);
}
else if (IconSource is BitmapIconSource bitmapIconSource)
{
_iconElement = new BitmapIcon();
SetIconBinding(_iconElement, nameof(bitmapIconSource.UriSource), BitmapIcon.UriSourceProperty);
SetIconBinding(_iconElement, nameof(bitmapIconSource.ShowAsMonochrome), BitmapIcon.ShowAsMonochromeProperty);
}
else if (IconSource is PathIconSource pathIconSource)
{
_iconElement = new PathIcon();
SetIconBinding(_iconElement, nameof(pathIconSource.Data), PathIcon.DataProperty);
}
if (_iconElement is not null)
{
if (IconSource.GetCurrentHighestValuePrecedence(IconSource.ForegroundProperty) < DependencyPropertyValuePrecedences.DefaultValue)
{
SetIconBinding(_iconElement, nameof(IconSource.Foreground), IconElement.ForegroundProperty);
}
AddIconChild(_iconElement);
}
}
private void SetIconBinding(IconElement iconElement, string path, DependencyProperty property)
{
var binding = new Binding()
{
Source = IconSource,
Path = new(path),
Mode = BindingMode.OneWay,
};
BindingOperations.SetBinding(iconElement, property, binding);
}
}
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
namespace Windows.UI.Xaml.Controls;
/// <summary>
/// Represents an icon that uses a vector path as its content.
/// </summary>
public partial class PathIcon : IconElement
{
private readonly Path _path;
/// <summary>
/// Initializes a new instance of the PathIcon class.
/// </summary>
public PathIcon()
{
_path = new Path();
AddIconChild(_path);
SynchronizeProperties();
}
/// <summary>
/// Gets or sets a Geometry that specifies the shape to be drawn. In XAML. this can also be set using a string that describes Move and draw commands syntax.
/// </summary>
public Geometry Data
{
get => (Geometry)GetValue(DataProperty);
set => SetValue(DataProperty, value);
}
/// <summary>
/// Identifies the Data dependency property.
/// </summary>
public static DependencyProperty DataProperty { get; } =
DependencyProperty.Register(
nameof(Data),
typeof(Geometry),
typeof(PathIcon),
new FrameworkPropertyMetadata(
null,
propertyChangedCallback: (s, e) => ((PathIcon)s)._path.Data = (Geometry)e.NewValue));
private void SynchronizeProperties()
{
_path.HorizontalAlignment = HorizontalAlignment.Stretch;
_path.VerticalAlignment = VerticalAlignment.Stretch;
_path.Fill = Foreground;
_path.Data = Data;
}
private protected override void OnForegroundChanged(DependencyPropertyChangedEventArgs e) =>
_path.Fill = (Brush)e.NewValue;
}
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Controls;
namespace Windows.UI.Xaml.Controls;
public partial class PathIconSource : IconSource
{
public PathIconSource()
{
}
public Geometry Data
{
get => (Geometry)GetValue(DataProperty);
set => SetValue(DataProperty, value);
}
public static DependencyProperty DataProperty { get; } =
DependencyProperty.Register(nameof(Data), typeof(Geometry), typeof(PathIconSource), new FrameworkPropertyMetadata(null));
public override IconElement CreateIconElement()
{
var pathIcon = new PathIcon();
if (Data != null)
{
pathIcon.Data = Data;
}
if (Foreground != null)
{
pathIcon.Foreground = Foreground;
}
return pathIcon;
}
}
#nullable enable
using Windows.UI.Text;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Automation;
using Windows.UI.Xaml.Automation.Peers;
namespace Windows.UI.Xaml.Controls;
/// <summary>
/// Represents an icon that uses a glyph from the Segoe MDL2 Assets font as its content.
/// </summary>
public sealed partial class SymbolIcon : IconElement
{
private const double DefaultFontSize = 20.0;
private readonly TextBlock _textBlock;
private static FontFamily? _symbolIconFontFamily;
/// <summary>
/// Initializes a new instance of the SymbolIcon class.
/// </summary>
public SymbolIcon() : this(Symbol.Emoji)
{
}
/// <summary>
/// Initializes a new instance of the SymbolIcon class using the specified symbol.
/// </summary>
/// <param name="symbol"></param>
public SymbolIcon(Symbol symbol)
{
_textBlock = new TextBlock();
AddIconChild(_textBlock);
Symbol = symbol;
SynchronizeProperties();
}
/// <summary>
/// Gets or sets the Segoe MDL2 Assets glyph used as the icon content.
/// </summary>
public Symbol Symbol
{
get => (Symbol)GetValue(SymbolProperty);
set => SetValue(SymbolProperty, value);
}
/// <summary>
/// Identifies the Symbol dependency property.
/// </summary>
public static DependencyProperty SymbolProperty { get; } =
DependencyProperty.Register(
nameof(Symbol),
typeof(Symbol),
typeof(SymbolIcon),
new FrameworkPropertyMetadata(Symbol.Emoji, propertyChangedCallback: (d, e) => ((SymbolIcon)d).SetSymbolText()));
private void SynchronizeProperties()
{
_textBlock.Style = null;
_textBlock.TextAlignment = Windows.UI.Xaml.TextAlignment.Center;
_textBlock.HorizontalAlignment = HorizontalAlignment.Stretch;
_textBlock.VerticalAlignment = VerticalAlignment.Center;
_textBlock.FontSize = DefaultFontSize;
_textBlock.FontStyle = FontStyle.Normal;
_textBlock.FontFamily = GetSymbolFontFamily();
_textBlock.IsTextScaleFactorEnabled = false;
_textBlock.SetValue(AutomationProperties.AccessibilityViewProperty, AccessibilityView.Raw);
SetSymbolText();
_textBlock.Foreground = Foreground;
}
private void SetSymbolText() => _textBlock.Text = new string((char)Symbol, 1);
private static FontFamily GetSymbolFontFamily() =>
_symbolIconFontFamily ??= new FontFamily(Uno.UI.FeatureConfiguration.Font.SymbolsFont);
private protected override void OnForegroundChanged(DependencyPropertyChangedEventArgs e) =>
_textBlock.Foreground = (Brush)e.NewValue;
}
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Windows.UI.Xaml.Controls;
public partial class SymbolIconSource : IconSource
{
public SymbolIconSource()
{
}
public Symbol Symbol
{
get => (Symbol)GetValue(SymbolProperty);
set => SetValue(SymbolProperty, value);
}
public static DependencyProperty SymbolProperty { get; } =
DependencyProperty.Register(nameof(Symbol), typeof(Symbol), typeof(SymbolIconSource), new FrameworkPropertyMetadata(Symbol.Emoji));
public override IconElement CreateIconElement()
{
var symbolIcon = new SymbolIcon()
{
Symbol = Symbol
};
if (Foreground != null)
{
symbolIcon.Foreground = Foreground;
}
return symbolIcon;
}
}
#if !__NETSTD_REFERENCE__
using System;
using System.Collections.Generic;
using System.Text;
using Uno.Extensions;
using Uno;
using Uno.UI.DataBinding;
using System.Linq;
using Windows.UI.Xaml.Shapes;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Controls;
#if XAMARIN_ANDROID
using View = Android.Views.View;
using ViewGroup = Android.Views.ViewGroup;
using Font = Android.Graphics.Typeface;
using Android.Graphics;
#elif XAMARIN_IOS_UNIFIED
using View = UIKit.UIView;
using ViewGroup = UIKit.UIView;
using Color = UIKit.UIColor;
using Font = UIKit.UIFont;
#elif XAMARIN_IOS
using View = MonoTouch.UIKit.UIView;
using ViewGroup = MonoTouch.UIKit.UIView;
using Color = MonoTouch.UIKit.UIColor;
using Font = MonoTouch.UIKit.UIFont;
#endif
namespace Windows.UI.Xaml.Controls
{
public partial class PathIcon : IconElement
{
private Shapes.Path _path;
public PathIcon()
{
_path = new Shapes.Path();
_path.Fill = Foreground;
_path.Stretch = Stretch.None;
AddIconElementView(_path);
}
public Geometry Data
{
get { return (Geometry)this.GetValue(DataProperty); }
set { this.SetValue(DataProperty, value); }
}
// Using a DependencyProperty as the backing store for Data. This enables animation, styling, binding, etc...
public static DependencyProperty DataProperty { get; } =
DependencyProperty.Register("Data", typeof(Geometry), typeof(PathIcon), new FrameworkPropertyMetadata(null, propertyChangedCallback: (s, e) => ((PathIcon)s).OnDataChanged(e)));
protected override void OnForegroundChanged(DependencyPropertyChangedEventArgs e)
{
_path.Fill = e.NewValue as Brush;
}
private void OnDataChanged(DependencyPropertyChangedEventArgs e)
{
_path.Data = e.NewValue as Geometry;
_path.Fill = Foreground;
}
}
}
#endif
#if XAMARIN || __WASM__ || __SKIA__
using System;
using Uno.UI.Controls;
using Windows.Foundation;
using Windows.Foundation.Metadata;
using Windows.UI.Xaml.Media;
namespace Windows.UI.Xaml.Controls
{
public sealed partial class SymbolIcon : IconElement
{
private FontIcon _icon;
public SymbolIcon() : this(Symbol.Emoji)
{
}
public SymbolIcon(Symbol symbol)
{
_icon = new FontIcon();
AddIconElementView(_icon);
_icon.Glyph = new string((char)symbol, 1);
}
public Symbol Symbol
{
get => (Symbol)GetValue(SymbolProperty);
set => SetValue(SymbolProperty, value);
}
public static DependencyProperty SymbolProperty { get; } =
DependencyProperty.Register(nameof(Symbol), typeof(Symbol), typeof(SymbolIcon), new FrameworkPropertyMetadata(Symbol.Emoji, OnSymbolChanged));
private static void OnSymbolChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
{
var symbol = dependencyObject as SymbolIcon;
if (symbol != null)
{
symbol._icon.Glyph = new string((char)symbol.Symbol, 1);
}
}
}
}
#endif
using Android.Views;
using Windows.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.Text;
namespace Windows.UI.Xaml.Controls
{
public partial class IconElement
{
partial void RegisterSubView(View child)
{
AddView(child);
}
}
}
......@@ -72,11 +72,11 @@ namespace UnoWinUIRevert
// Files/Class that are implemented in both MUX and WUX and which should not be converted
var duplicatedImplementations = new[]
{
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Icon\BitmapIconSource.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Icon\SymbolIconSource.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Icon\PathIconSource.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Icon\FontIconSource.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Icon\IconSource.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Icons\BitmapIconSource.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Icons\SymbolIconSource.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Icons\PathIconSource.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Icons\FontIconSource.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Icons\IconSource.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Unsupported\RatingControl.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Automation\Peers\RatingControlAutomationPeer.cs"),
Path.Combine(basePath, @"src\Uno.UI\UI\Xaml\Controls\Unsupported\SplitButton.cs"),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册