Repository navigation
Description
Part of effort - #8655
Background and motivation
Icons are an important part of Win11 design system. With the release of Windows 11, the Segoe Fluent Icons font is the recommended symbol icon font. In this proposal, we have the API changes for supporting symbol icon font with ease in WPF applications.
User Scenarios
- [P1] Application developers should be able to use Windows 11 system icon font to render icons in the application.
- [P1] Application developers can use custom font icons in there WPF applications.
- [P1] Developers have the freedom to modify the size, style, weight of the font icons.
- [P2] Application developers should be able to use markup extensions to set icon
- [P3] Application developers can use icon names to render commonly used icons.
- [P3] Application developers can use other objects like Path, Image, Bitmap, etc as icon. Provide extensibility for the same.
Code Example
<FontIcon FontSize="16" Glyph="Σ"
FontFamily="Segoe Fluent Icons"
FontWeight="Bold" />
<IconSourceElement>
<IconSourceElement.IconSource>
<FontIconSource Glyph="Σ" FontFamily="Segoe Fluent Icons">
</IconSourceElement.IconSource>
</IconSourceElement> var fontIcon = new FontIcon();
fontIcon.FontFamily = new FontFamily("Segoe Fluent Icons");
fontIcon.Glyph = "\xE790";API Proposals Iteration 1
IconElement
- Provides the base class support for adding icon related feature to controls.
+ [System.ComponentModel.TypeConverterAttribute(typeof(System.Windows.Controls.IconElementConverter))]
+ public abstract class IconElement : System.Windows.FrameworkElement
+ {
+ protected abstract System.Windows.UIElement InitializeChildren();
+ protected IconElement() { }
+ public static readonly System.Windows.DependencyProperty ForegroundProperty;
+ [System.ComponentModel.BindableAttribute(true)]
+ [System.ComponentModel.CategoryAttribute("Appearance")]
+ public System.Windows.Media.Brush Foreground { get; set; }
+ protected override int VisualChildrenCount { get; }
+ protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize);
+ protected override System.Windows.Media.Visual GetVisualChild(int index);
+ protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize);
+ }FontIcon
- Concrete class that implements
IconElement. Represents an icon that uses a glyph from the specified font. - Defines following dependency properties -
- FontFamily : Gets or sets the font used to display the icon glyph.
- FontSize : Gets or sets the size of the icon glyph.
- FontStyle : Gets or sets the font style for the icon glyph.
- FontWeight : Gets or sets the thickness of the icon glyph
- Glyph : Gets or sets the character code that identifies the icon glyph.
+ public class FontIcon : System.Windows.Controls.IconElement
+ {
+ public FontIcon() { }
+ public static readonly System.Windows.DependencyProperty FontFamilyProperty;
+
+ [System.ComponentModel.BindableAttribute(true)]
+ [System.ComponentModel.CategoryAttribute("Appearance")]
+ [System.Windows.LocalizabilityAttribute(System.Windows.LocalizationCategory.Font)]
+ public System.Windows.Media.FontFamily FontFamily { get; set; }
+
+
+ public static readonly System.Windows.DependencyProperty FontSizeProperty;
+
+ [System.ComponentModel.BindableAttribute(true)]
+ [System.ComponentModel.CategoryAttribute("Appearance")]
+ [System.ComponentModel.TypeConverterAttribute(typeof(System.Windows.FontSizeConverter))]
+ [System.Windows.LocalizabilityAttribute(System.Windows.LocalizationCategory.None)]
+ public double FontSize { get; set; }
+ public static readonly System.Windows.DependencyProperty FontStyleProperty;
+ [System.ComponentModel.BindableAttribute(true)]
+ [System.ComponentModel.CategoryAttribute("Appearance")]
+ public System.Windows.FontStyle FontStyle { get; set; }
+ public static readonly System.Windows.DependencyProperty FontWeightProperty;
+ [System.ComponentModel.BindableAttribute(true)]
+ [System.ComponentModel.CategoryAttribute("Appearance")]
+ public System.Windows.FontWeight FontWeight { get; set; }
+ public static readonly System.Windows.DependencyProperty GlyphProperty;
+ public string Glyph { get; set; }
+ protected override System.Windows.UIElement InitializeChildren();
+ }IconSourceElement
- Represents an icon element that uses an
IconSourceobject as its content.
+ [System.Windows.Markup.ContentPropertyAttribute("IconSource")]
+ public class IconSourceElement : System.Windows.Controls.IconElement
+ {
+ public IconSourceElement() { }
+ public static readonly System.Windows.DependencyProperty IconSourceProperty;
+ public System.Windows.Controls.IconSource IconSource { get; set; }
+ protected override System.Windows.UIElement InitializeChildren();
+ }ImageIcon
- Represents an icon that uses an
System.Windows.Controls.Imageas its content.
+ [System.Windows.Markup.ContentPropertyAttribute("IconSource")]
+ public class ImageIcon : System.Windows.Controls.IconElement
+ {
+ public ImageIcon() { }
+ public static readonly System.Windows.DependencyProperty SourceProperty;
+ public System.Windows.Controls.ImageSource Source { get; set; }
+ protected override System.Windows.UIElement InitializeChildren();
+ }IconSource
- Represents a base class for an icon source. We can use this in combination with
IconSourceElementto add icons to WPF applications. This is similar toIconElement, however since this is not aFrameworkElementit can be shared.
+ public abstract class IconSource : System.Windows.DependencyObject
+ {
+ protected IconSource() { }
+ public static readonly System.Windows.DependencyProperty ForegroundProperty;
+ public System.Windows.Media.Brush Foreground { get; set; }
+ public abstract System.Windows.Controls.IconElement CreateIconElement();
+ }FontIconSource
- Represents an icon source that uses a glyph from the specified font.
+ public class FontIconSource : IconSource
+ {
+ public FontIconSource() { }
+ public static readonly System.Windows.DependencyProperty FontFamilyProperty;
+ public System.Windows.Media.FontFamily FontFamily { get; set; }
+ public static readonly System.Windows.DependencyProperty FontSizeProperty;
+ public double FontSize { get; set; }
+ public static readonly System.Windows.DependencyProperty FontStyleProperty;
+ public System.Windows.FontStyle FontStyle { get; set; }
+ public static readonly System.Windows.DependencyProperty FontWeightProperty;
+ public System.Windows.FontWeight FontWeight { get; set; }
+ public static readonly System.Windows.DependencyProperty GlyphProperty;
+ public string Glyph { get; set; }
+ public override System.Windows.Controls.IconElement CreateIconElement();
+ }IconSourceElementConverter
- Converting an
IconSourceElementtoIconElement
+ public partial class IconSourceElementConverter : System.Windows.Data.IValueConverter
+ {
+ public IconSourceElementConverter() { }
+ public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture);
+ public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture);
+ }ImageIconExtension
- Custom markup extension that provides
ImageIcon
Usage -
<.... Icon="{ImageIcon 'pack://application:,,,/Assets/icon.png'}" ... />
+ [ContentProperty(nameof(Source))]
+ [MarkupExtensionReturnType(typeof(ImageIcon))]
+ public class ImageIconExtension : MarkupExtension
+ {
+ public ImageIconExtension(ImageSource? source);
+
+ [ConstructorArgument("source")]
+ public ImageSource? Source { get; set; }
+
+ public double Width { get; set; } = 16D;
+
+ public double Height { get; set; } = 16D;
+
+ public override object ProvideValue(IServiceProvider serviceProvider);
+ }FontIconExtension
- Custom markup extension that provides
FontIcon
Usage -
<.... Icon="{FontIcon Glyph="'&#x1F308;'" FontFamily="Cascadia" FontSize=10 }" ... />
+ [ContentProperty(nameof(Glyph))]
+ [MarkupExtensionReturnType(typeof(FontIcon))]
+ public class FontIconExtension : MarkupExtension
+ {
+ public FontIconExtension(string glyph);
+
+ public FontIconExtension(string glyph, FontFamily fontFamily): this(glyph);
+
+ [ConstructorArgument("glyph")]
+ public string Glyph { get; set; }
+
+ [ConstructorArgument("fontFamily")]
+ public FontFamily FontFamily { get; set; }
+
+ public double FontSize { get; set; }
+
+ public override object ProvideValue(IServiceProvider serviceProvider);
+ }Alternative Designs
In an another approach for the above, we can eliminate derived classes of IconElement, have an IconSource property in IconElement, and we keep IconSource and derived classes ( FontIconSource, ImageIconSource, ...) alongwith corresponding icon source extensions ( FontIconSourceExtension, ImageIconSourceExtension, ... ).
If we follow this approach, the usage of APIs will be as follows:
<IconElement>
<IconElement.IconSource>
<FontIconSource Glyph="Σ" FontFamily="Segoe Fluent Icons">
</IconElement.IconSource>
</IconElement>
<IconElement IconSource="{FontIconSource 'Σ' }"> var iconElement = new IconElement();
var fontIconSource = new FontIconSource();
fontIconSource.FontFamily = new FontFamily("Segoe Fluent Icons");
fontIconSource.Glyph = "\xE790";IconElement
As mentioned above, here is the IconElement API for the above approach:
public partial class IconElement : System.Windows.FrameworkElement
{
public IconElement() { }
public static readonly System.Windows.DependencyProperty IconSourceProperty;
public System.Windows.Controls.IconSource IconSource { get { throw null; } set { } }
protected virtual System.Windows.UIElement InitializeChildren() { throw null; }
protected override int VisualChildrenCount { get { throw null; } }
protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize) { throw null; }
protected override System.Windows.Media.Visual GetVisualChild(int index) { throw null; }
protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize) { throw null; }
}IconSource, FontIconSource, FontIconSourceExtension, ...
public abstract partial class IconSource : System.Windows.DependencyObject
{
protected IconSource() { }
public static readonly System.Windows.DependencyProperty ForegroundProperty;
public System.Windows.Media.Brush Foreground { get { throw null; } set { } }
public abstract System.Windows.UIElement CreateIconContent();
}
public partial class FontIconSource : System.Windows.Controls.IconSource
{
public FontIconSource() { }
public static readonly System.Windows.DependencyProperty FontFamilyProperty;
public static readonly System.Windows.DependencyProperty FontSizeProperty;
public static readonly System.Windows.DependencyProperty FontStyleProperty;
public static readonly System.Windows.DependencyProperty FontWeightProperty;
public static readonly System.Windows.DependencyProperty GlyphProperty;
public System.Windows.Media.FontFamily FontFamily { get { throw null; } set { } }
public double FontSize { get { throw null; } set { } }
public System.Windows.FontStyle FontStyle { get { throw null; } set { } }
public System.Windows.FontWeight FontWeight { get { throw null; } set { } }
public string Glyph { get { throw null; } set { } }
public override System.Windows.UIElement CreateIconContent() { throw null; }
}
[System.Windows.Markup.ContentPropertyAttribute("Glyph")]
[System.Windows.Markup.MarkupExtensionReturnTypeAttribute(typeof(System.Windows.Controls.FontIconSource))]
public partial class FontIconSourceExtension : System.Windows.Markup.MarkupExtension
{
public FontIconSourceExtension(string glyph) { }
public FontIconSourceExtension(string glyph, System.Windows.Media.FontFamily fontFamily) { }
[System.Windows.Markup.ConstructorArgumentAttribute("fontFamily")]
public System.Windows.Media.FontFamily FontFamily { get { throw null; } set { } }
public double FontSize { get { throw null; } set { } }
[System.Windows.Markup.ConstructorArgumentAttribute("glyph")]
public string Glyph { get { throw null; } set { } }
public override object ProvideValue(System.IServiceProvider serviceProvider) { throw null; }
}Risks
Unknown
cc: @dotnet/dotnet-wpf-triage @pomianowski
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields☑ Done
Activity
miloush commentedon Jan 8, 2024
So are these not for discussion or what is the status of the theming API proposals?
pchaurasia14 commentedon Jan 8, 2024
@miloush - These were generated via automated build differences. I'm making the edits to make it more easier to review. Once done, we can discuss them. Same with the other API proposals. Should be ready in a day or two.
lindexi commentedon Jan 9, 2024
@pchaurasia14 Will the field of
FontIcon.TextBlockbreak the dotnet design standard?See https://github.com/dotnet/docs/blob/main/docs/standard/design-guidelines/field.md
pchaurasia14 commentedon Jan 9, 2024
@lindexi - Yup. I've corrected it.
miloush commentedon Jan 9, 2024
SymbolRegularis missing?miloush commentedon Jan 9, 2024
Is this modeled after other frameworks? UWP/WinUI/MAUI?
Icon="{FontIcon Glyph="'&#x1F308;'" FontFamily="Cascadia" FontSize=10 }"is probably invalid syntax with the quotesWhy
IIconControlrather than[IconProperty("Icon")]?Why
protected IconElement.OnForegroundPropertyChanged? Derived classes can override the DP metadata.Why the explicit control properties like
FontIcon.TextBlock,ImageIcon.Image? Isn't the idea of WPF that the controls are UI-less and the UI is provided with templates?It is a bit weird to call
Glypha property that actually means character, not a font glyph (shouldn't we support glyphs too btw.?). But if other API already uses it, I guess it's ok.Shouldn't boolean properties like
SymbolIcon.FilledbeIsFilled?Why is
IconSourceElementneeded? Does not seem to be used by any of the classes.Don't the icon sources need not to be
Animatable? Why are they not image sources (or drawings where appropriate, there is already a GlyphRunDrawing)?Finally, why does
IconElementeven need to exist? Its only purpose seems to have aForegroundproperty. What does theImageIconneed a foreground for? Moreover, it would confusingly not apply to drawings image sources.FontIconseems to be better class to have aForegroundproperty.pchaurasia14 commentedon Jan 9, 2024
@miloush - Thanks for the questions.
I've added the link to the file.
I don't think it is. We will take a look at them and see how we can bring uniformity to APIs.
For the other changes, I think we'll need to first decide on the high level API changes and then trim down the supporting abstractions.
12 remaining items
batzen commentedon Mar 5, 2024
I still don't understand the need for all those new classes.
It would be nice to get an explanation from the team.
As far as I can see all of this, aside from some missing markup extensions, can be achieved with existing classes.
KirillOsenkov commentedon Mar 5, 2024
@terrajobst @bartonjs I really feel that this is rushed and it's not clear that this is a beneficial change at all.
I strongly agree with @batzen and @miloush and share his and others' concerns. This is a significant addition to the public API that in my view isn't warranted.
Can we make sure these are absolutely necessary? I'd like at the very least to see a small real WPF app that is using this API and an equivalent that just uses the existing API surface. I'd like it compared side-by-side.
It's strange to ship an API without a clear and compelling usage example that is real and not contrived.
miloush commentedon Mar 6, 2024
For those who have not seen the recording, this was approved so that it can become part of public preview, with the anticipation that it will need changes and re-approval following feedback from the community. I would therefore encourage people to not give up and keep voicing their concerns.
It should also be said the proposed design seems to mirror WinUI. Note however, that WinUI does not have any vector
Drawingsupport. I suspect much of the design there comes from this gap.I agree that I am not convinced at all that the proposed infrastructure is needed. Based on the Alternative 2, I see two desires:
ContentControlhaving aContent, or, much more alike,HeaderforHeaderedContentControlandHeaderedItemsControl, and wasn't sure why are these two not satisfactory for the same purpose asIconElement. Now I am realizing that the elements are probably not supposed to render anything else other than the icon, in which case the question is how are they different fromImages?In what way is
better than
?
TextBlockcould be used for this purpose, but there is also the GlyphRun and corresponding Glyphs element. Most notably, there already is aGlyphRunDrawingthat can be used as an image source. These options are not available in the WinUI platform. I do admit, however, that they are quite complicated to use. There could indeed be a markup extension that produces aDrawingImagewithGlyphRunDrawing, or some kind ofGlyphImageorGlyphRunImage : DrawingImagethat would simplify this usage. I do not however see a point ofIconSourcebeing distinct from and not anImageSource(it is also confusing with the term "Icon" as inIconBitmapDecoder).(I also reiterate my reservations against
Glyphproperty when it doesn't mean a glyph in the font terminology.)The API proposals tend to be out of context and do not show how they are planned to be used in wider context (not even in the Win11 templates) or implemented. As @KirillOsenkov suggested, some demonstration would be very useful.
singhashish-wpf commentedon Mar 6, 2024
@batzen @miloush @KirillOsenkov
Thanks for bringing these gaps to our knowledge.
This proposal was created with the intent of bringing first class support for Icons in WPF and to bring WPF to parity with WinUI in terms of Icon support.
From the above discussions there are concerns with the current state of the proposal and we will not be implementing this in its current state. We are anticipating more changes to this as per the feedback received, and they will be implemented only once there is an agreement with the proposal (as was stated in the API Proposal discussion meeting). We will provide more usage examples and side-by-side comparisons of approaches as requested. We are also open to receiving alternative designs to provide first-class support for Icons in WPF.
miloush commentedon Mar 6, 2024
@singhashish-wpf I think part of the issue is that as far as I can tell from the issue tracker, no one really asked for "first class support for Icons", it is not clear what an "Icon" means and why is such support needed. It would be good to have these discussions before an API surface is put for approval.
It looked like "Icons" are needed for the Win11 theme effort, but that is perhaps not really the case and should stand their ground on their own.
KirillOsenkov commentedon Mar 6, 2024
Also the best API normally emerges from usage, after refactoring and making sure it solves the actual problem well. Perhaps even test-driven, where you write usage first and then define the API to make the tests pass.
An experienced WPF developer should look at an API and immediately understand what it is for and how to use it. The roles should be clearly defined, like what is a Control, what is a Visual, what is a Panel. This is not the case here.
I do appreciate the work that was put in though!
dipeshmsft commentedon Jan 21, 2025
Closing this API Proposal as we are not moving ahead with this.