Skip to content

Commit

Permalink
Fixed the FontIcon markup extension
Browse files Browse the repository at this point in the history
  • Loading branch information
m0lDaViA committed Mar 28, 2024
1 parent ccc2e44 commit f24ee30
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/Wpf.Ui/Controls/ComboBox/ComboBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
<ControlTemplate TargetType="{x:Type TextBox}">
<controls:PassiveScrollViewer
x:Name="PART_ContentHost"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Style="{DynamicResource DefaultTextBoxScrollViewerStyle}"
TextElement.Foreground="{TemplateBinding Foreground}" />
</ControlTemplate>
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui/Controls/IconElement/FontIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public FontWeight FontWeight
/// Gets or sets the character code that identifies the icon glyph.
/// </summary>
/// <returns>The hexadecimal character code for the icon glyph.</returns>
public string Glyph
public string? Glyph
{
get => (string)GetValue(GlyphProperty);
set => SetValue(GlyphProperty, value);
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui/Controls/ListView/ListViewItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</ControlTemplate.Triggers>
</ControlTemplate>

<ControlTemplate x:Key="GridViewItemTemplate" TargetType="{x:Type controls:ListViewItem}">
<ControlTemplate x:Key="GridViewItemTemplate" TargetType="{x:Type controls:ListViewItem}">
<Border
x:Name="Border"
Margin="0"
Expand Down
16 changes: 8 additions & 8 deletions src/Wpf.Ui/Controls/NumberBox/NumberBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
<Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Border
x:Name="ContentBorder"
MinWidth="{TemplateBinding MinWidth}"
MinHeight="{TemplateBinding MinHeight}"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
MinWidth="{TemplateBinding MinWidth}"
MinHeight="{TemplateBinding MinHeight}"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Expand All @@ -82,8 +82,8 @@
VerticalAlignment="Top"
Content="{TemplateBinding Icon}"
FontSize="16"
IsTabStop="False"
Foreground="{TemplateBinding Foreground}" />
Foreground="{TemplateBinding Foreground}"
IsTabStop="False" />
<Grid Grid.Column="1" Margin="{TemplateBinding Padding}">
<controls:PassiveScrollViewer
x:Name="PART_ContentHost"
Expand Down Expand Up @@ -115,8 +115,8 @@
Command="{Binding Path=TemplateButtonCommand, RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="clear"
Cursor="Arrow"
IsTabStop="False"
Foreground="{DynamicResource TextControlButtonForeground}">
Foreground="{DynamicResource TextControlButtonForeground}"
IsTabStop="False">
<controls:Button.Icon>
<controls:SymbolIcon FontSize="{StaticResource NumberBoxButtonIconSize}" Symbol="Dismiss24" />
</controls:Button.Icon>
Expand Down Expand Up @@ -178,8 +178,8 @@
VerticalAlignment="Top"
Content="{TemplateBinding Icon}"
FontSize="16"
IsTabStop="False"
Foreground="{TemplateBinding Foreground}" />
Foreground="{TemplateBinding Foreground}"
IsTabStop="False" />
</Grid>
</Border>
<!-- The Accent Border is a separate element so that changes to the border thickness do not affect the position of the element -->
Expand Down
8 changes: 4 additions & 4 deletions src/Wpf.Ui/Controls/PasswordBox/PasswordBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@
Command="{Binding Path=TemplateButtonCommand, RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="clear"
Cursor="Arrow"
IsTabStop="False"
Foreground="{DynamicResource TextControlButtonForeground}">
Foreground="{DynamicResource TextControlButtonForeground}"
IsTabStop="False">
<controls:Button.Icon>
<controls:SymbolIcon FontSize="{StaticResource PasswordBoxButtonIconSize}" Symbol="Dismiss24" />
</controls:Button.Icon>
Expand All @@ -228,8 +228,8 @@
Command="{Binding Path=TemplateButtonCommand, RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="reveal"
Cursor="Arrow"
IsTabStop="False"
Foreground="{DynamicResource TextControlButtonForeground}">
Foreground="{DynamicResource TextControlButtonForeground}"
IsTabStop="False">
<controls:Button.Icon>
<controls:SymbolIcon FontSize="{StaticResource PasswordBoxButtonIconSize}" Symbol="Eye24" />
</controls:Button.Icon>
Expand Down
4 changes: 2 additions & 2 deletions src/Wpf.Ui/Controls/TitleBar/TitleBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@
x:Name="PART_CloseButton"
Grid.Column="4"
ButtonType="Close"
MouseOverButtonsForeground="White"
MouseOverBackground="{DynamicResource PaletteRedBrush}" />
MouseOverBackground="{DynamicResource PaletteRedBrush}"
MouseOverButtonsForeground="White" />
</Grid>
</Grid>
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions src/Wpf.Ui/Extensions/SymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public static SymbolRegular Swap(this SymbolFilled icon)
/// <summary>
/// Converts <see cref="SymbolRegular"/> to <see langword="string"/> based on the ID.
/// </summary>
public static string GetString(this SymbolRegular icon)
public static string? GetString(this SymbolRegular icon)
{
return Encoding.Unicode.GetString(BitConverter.GetBytes((int)icon)).TrimEnd('\0');
}

/// <summary>
/// Converts <see cref="SymbolFilled"/> to <see langword="string"/> based on the ID.
/// </summary>
public static string GetString(this SymbolFilled icon)
public static string? GetString(this SymbolFilled icon)
{
return Encoding.Unicode.GetString(BitConverter.GetBytes((int)icon)).TrimEnd('\0');
}
Expand Down
22 changes: 12 additions & 10 deletions src/Wpf.Ui/Markup/FontIconExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,31 @@ namespace Wpf.Ui.Markup;
[MarkupExtensionReturnType(typeof(FontIcon))]
public class FontIconExtension : MarkupExtension
{
public FontIconExtension(string glyph)
public FontIconExtension()
{
Glyph = glyph;
FontFamily = new FontFamily("FluentSystemIcons");
}

public FontIconExtension(string glyph, FontFamily fontFamily)
: this(glyph)
public FontIconExtension(string glyph)
{
FontFamily = fontFamily;
Glyph = glyph;
}

[ConstructorArgument("glyph")]
public string Glyph { get; set; }
public string? Glyph { get; set; }

[ConstructorArgument("fontFamily")]
public FontFamily FontFamily { get; set; }
public FontFamily FontFamily { get; set; } = new("FluentSystemIcons");

public double FontSize { get; set; }

public override object ProvideValue(IServiceProvider serviceProvider)
{
var fontIcon = new FontIcon { Glyph = Glyph, FontFamily = FontFamily };
if (serviceProvider.GetService(typeof(IProvideValueTarget)) is IProvideValueTarget { TargetObject: Setter })
{
return this;
}

FontIcon fontIcon = new() { Glyph = Glyph, FontFamily = FontFamily };

if (FontSize > 0)
{
Expand All @@ -63,4 +65,4 @@ public override object ProvideValue(IServiceProvider serviceProvider)

return fontIcon;
}
}
}
3 changes: 1 addition & 2 deletions src/Wpf.Ui/Resources/DefaultTextBoxScrollViewerStyle.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<!-- TODO: Rework TextBox ScrollViewer -->
<Style x:Key="DefaultTextBoxScrollViewerStyle" TargetType="{x:Type ScrollViewer}">
Expand Down

0 comments on commit f24ee30

Please sign in to comment.