Skip to content
Open
1 change: 1 addition & 0 deletions src/Wpf.Ui.Gallery/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:syntax="http://schemas.lepo.co/wpfui/2022/xaml/syntax"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
DispatcherUnhandledException="OnDispatcherUnhandledException"
xmlns:system="clr-namespace:System;assembly=mscorlib"
Exit="OnExit"
Startup="OnStartup">
<Application.Resources>
Expand Down
44 changes: 44 additions & 0 deletions src/Wpf.Ui.Gallery/Views/Pages/BasicInput/ButtonPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,50 @@
Icon="{ui:SymbolIcon Fluent24}" />
</controls:ControlExample>

<controls:ControlExample
Margin="0,32,0,0"
HeaderText="WPF UI Brush icon."
XamlCode="&lt;ui:Button Appearance=&quot;Primary&quot; /&gt;">
<controls:ControlExample.Resources>
<DrawingBrush x:Key="JSPhone">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M3,16L14.001,16 14.001,0 3,0z" />
<GeometryDrawing Brush="#FFF16320" Geometry="F1M12,12L5,12 5,2 12,2z M12,14L11,14 11,13 12,13z M9,14L8,14 8,13 9,13z M6,14L5,14 5,13 6,13z M4,15L13,15 13,1 4,1z" />
<GeometryDrawing Brush="#FFF0EFF1" Geometry="F1M12,12L5,12 5,2 12,2z" />
<GeometryDrawing Brush="#FFF0EFF1" Geometry="F1M5,14L6,14 6,13 5,13z" />
<GeometryDrawing Brush="#FFF0EFF1" Geometry="F1M8,14L9,14 9,13 8,13z" />
<GeometryDrawing Brush="#FFF0EFF1" Geometry="F1M11,14L12,14 12,13 11,13z" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>

<DrawingBrush x:Key="StatusCriticalError" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M16,8C16,12.418 12.418,16 8,16 3.582,16 0,12.418 0,8 0,3.582 3.582,0 8,0 12.418,0 16,3.582 16,8" />
<GeometryDrawing Brush="#FFE41400" Geometry="F1M12.4141,11L11.0001,12.414 8.0001,9.414 5.0001,12.414 3.5871,11 6.5861,8 3.5871,5 5.0001,3.586 8.0001,6.586 11.0001,3.586 12.4141,5 9.4141,8z M8.0001,1C4.1351,1 1.0001,4.135 1.0001,8 1.0001,11.865 4.1351,15 8.0001,15 11.8651,15 15.0001,11.865 15.0001,8 15.0001,4.135 11.8651,1 8.0001,1" />
<GeometryDrawing Brush="#FFFFFFFF" Geometry="F1M9.4141,8L12.4141,11 11.0001,12.414 8.0001,9.414 5.0001,12.414 3.5861,11 6.5861,8 3.5861,5 5.0001,3.586 8.0001,6.586 11.0001,3.586 12.4141,5z" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</controls:ControlExample.Resources>
<StackPanel>

<ui:Button
Appearance="Primary"
Content="WPF UI button" FontSize="20" FontWeight="Black"
Icon="{ui:DrawingBrushIcon {StaticResource StatusCriticalError}, Size=24}">
</ui:Button>
</StackPanel>
</controls:ControlExample>

<controls:ControlExample
Margin="0,32,0,0"
HeaderText="WPF UI button with FontIcon."
Expand Down
89 changes: 89 additions & 0 deletions src/Wpf.Ui/Controls/IconElement/DrawingBrushIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


using System.Windows.Controls;

namespace Wpf.Ui.Controls;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
namespace Wpf.Ui.Controls;
namespace Wpf.Ui.Controls;


/// <summary>
/// Represents an icon that uses an DrawingBrush as its content.
/// </summary>
public class DrawingBrushIcon : IconElement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docs for the public API

{
/// <summary>
/// Gets or sets <see cref="Icon"/>
/// </summary>
public DrawingBrush Icon
{
get { return (DrawingBrush)GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}

/// <summary>Identifies the <see cref="Icon"/> dependency property.</summary>
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(
nameof(Icon),
typeof(DrawingBrush),
typeof(DrawingBrushIcon),
new PropertyMetadata(default(DrawingBrush), OnIconChanged));

private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var self = (DrawingBrushIcon)d;
if (self.Border is null)
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing brackets according to the .editorconfig


self.Border.Background = e.NewValue as DrawingBrush;
}

/// <summary>
/// Gets or sets <see cref="Size"/>
/// </summary>
public double Size
{
get { return (double)GetValue(SizeProperty); }
set { SetValue(SizeProperty, value); }
}

/// <summary>Identifies the <see cref="Size"/> dependency property.</summary>
public static readonly DependencyProperty SizeProperty = DependencyProperty.Register(
nameof(Size),
typeof(double),
typeof(DrawingBrushIcon),
new PropertyMetadata(16.0, OnIconSizeChanged));

private static void OnIconSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var self = (DrawingBrushIcon)d;
if (self.Border is null)
{
return;
}

if (double.TryParse(e.NewValue?.ToString(), out double dblValue))
{
self.Border.Width = dblValue;
self.Border.Height = dblValue;
}
}

protected Border? Border;

protected override UIElement InitializeChildren()
{
Border = new Border()
{
HorizontalAlignment = HorizontalAlignment.Stretch,
Background = Icon,
Width = Size,
Height = Size
};

Viewbox viewbox = new Viewbox();
viewbox.Child = Border;

return viewbox;
}
}
54 changes: 35 additions & 19 deletions src/Wpf.Ui/Controls/NavigationView/NavigationViewCompact.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<Border
x:Name="MainBorder"
Grid.Row="0"
MinWidth="40"
MinHeight="40"
MinWidth="{DynamicResource PaneLeftButtonWidth}"
MinHeight="{DynamicResource PaneLeftButtonHeight}"
Margin="0"
Padding="0"
BorderBrush="{TemplateBinding BorderBrush}"
Expand All @@ -36,14 +36,15 @@
</Border.Style>
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Grid Grid.Column="0">
<ContentPresenter
<Grid Grid.Column="0" Width="{DynamicResource PaneLeftButtonWidth}">
<Viewbox Width="{DynamicResource NavigationViewLeftIconSize}">
<ContentPresenter
x:Name="IconContentPresenter"
Margin="-1,0,0,0"
HorizontalAlignment="Center"
Expand All @@ -52,13 +53,14 @@
Focusable="False"
TextElement.FontSize="16"
TextElement.Foreground="{DynamicResource NavigationViewItemForeground}" />
</Viewbox>
</Grid>

<Rectangle
x:Name="ActiveRectangle"
Grid.Column="0"
Width="3"
Height="16"
Height="{DynamicResource NavigationViewItemActiveRectangleHeight}"
Margin="0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Expand Down Expand Up @@ -125,7 +127,7 @@
<ControlTemplate TargetType="{x:Type controls:NavigationViewItem}">
<Border
x:Name="MainBorder"
Height="40"
Height="{DynamicResource PaneLeftButtonHeight}"
HorizontalAlignment="Stretch"
BorderThickness="1"
CornerRadius="4">
Expand Down Expand Up @@ -211,7 +213,7 @@
</Trigger>
<Trigger Property="HasMenuItems" Value="True">
<Setter TargetName="PART_ChevronGrid" Property="Visibility" Value="Visible" />
<Setter TargetName="PART_ChevronGrid" Property="Width" Value="40" />
<Setter TargetName="PART_ChevronGrid" Property="Width" Value="{DynamicResource PaneLeftButtonWidth}" />
</Trigger>
<Trigger Property="IsExpanded" Value="True">
<Setter TargetName="MenuItemsPresenter" Property="Visibility" Value="Visible" />
Expand Down Expand Up @@ -307,6 +309,8 @@
Grid.Row="0"
Margin="0,5,0,5"
HorizontalAlignment="Left"
Width="{DynamicResource PaneLeftButtonWidth}"
Height="{DynamicResource PaneLeftButtonHeight}"
IsEnabled="{TemplateBinding IsBackEnabled}"
Style="{StaticResource BasePaneButtonStyle}"
Visibility="{TemplateBinding IsBackButtonVisible,
Expand All @@ -316,20 +320,30 @@
</controls:Button.Icon>
</controls:Button>

<controls:Button
x:Name="PART_ToggleButton"
<Grid x:Name="PART_ToggleButtonGrid" Grid.Row="1" HorizontalAlignment="Left"
Visibility="{TemplateBinding IsPaneToggleVisible,
Converter={StaticResource BoolToVisibilityConverter}}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<Viewbox Width="{DynamicResource PaneLeftButtonWidth}">
<controls:Button
x:Name="PART_ToggleButton"
Grid.Row="1"
Margin="0,0,0,5"
Style="{StaticResource BasePaneButtonStyle}"
Visibility="{TemplateBinding IsPaneToggleVisible,
Converter={StaticResource BoolToVisibilityConverter}}">
<controls:Button.Icon>
<controls:SymbolIcon Symbol="LineHorizontal320" />
</controls:Button.Icon>
<controls:Button.Content>
<TextBlock FontWeight="Medium" Text="{TemplateBinding PaneTitle}" />
</controls:Button.Content>
</controls:Button>
<controls:Button.Icon>
<controls:SymbolIcon Symbol="LineHorizontal320"/>
</controls:Button.Icon>
</controls:Button>
</Viewbox>

<TextBlock x:Name="PART_PaneTitle" Grid.Column="1" FontWeight="Medium" Text="{TemplateBinding PaneTitle}" />
</Grid>

<!-- Pane header -->
<ContentPresenter
Expand Down Expand Up @@ -449,7 +463,7 @@
AccelerationRatio="0.4"
Storyboard.TargetName="PaneGrid"
Storyboard.TargetProperty="Width"
From="40"
From="{DynamicResource PaneLeftButtonWidth}"
To="{TemplateBinding OpenPaneLength}"
Duration="0:0:.16" />
</Storyboard>
Expand All @@ -461,7 +475,7 @@
Storyboard.TargetName="PaneGrid"
Storyboard.TargetProperty="Width"
From="{TemplateBinding OpenPaneLength}"
To="40"
To="{DynamicResource PaneLeftButtonWidth}"
Duration="0:0:.16" />
</Storyboard>
</VisualState>
Expand All @@ -474,13 +488,15 @@
<Setter TargetName="PART_AutoSuggestBoxSymbolButton" Property="Visibility" Value="Visible" />
<Setter TargetName="AutoSuggestBoxContentPresenter" Property="Visibility" Value="Collapsed" />
<Setter TargetName="PART_ToggleButton" Property="Content" Value="{x:Null}" />
<Setter TargetName="PART_PaneTitle" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="AutoSuggestBox" Value="{x:Null}">
<Setter TargetName="PART_AutoSuggestBoxSymbolButton" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="PaneTitle" Value="{x:Null}">
<Setter TargetName="PART_ToggleButton" Property="Content" Value="{x:Null}" />
<Setter TargetName="PART_ToggleButton" Property="HorizontalAlignment" Value="Left" />
<Setter TargetName="PART_PaneTitle" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
xmlns:converters="clr-namespace:Wpf.Ui.Converters"
xmlns:system="clr-namespace:System;assembly=mscorlib">

<system:Double x:Key="NavigationViewLeftIconSize">12</system:Double>
<system:Double x:Key="NavigationViewItemActiveRectangleHeight">16</system:Double>
<system:Double x:Key="PaneLeftButtonHeight">40</system:Double>
<system:Double x:Key="PaneLeftButtonWidth">40</system:Double>

<system:Double x:Key="NavigationViewFluentIconSize">24</system:Double>
<system:Double x:Key="PaneToggleButtonHeight">40</system:Double>
<system:Double x:Key="PaneToggleButtonWidth">40</system:Double>
<system:Double x:Key="PaneFluentButtonHeight">60</system:Double>
<system:Double x:Key="PaneFluentButtonWidth">60</system:Double>
<system:Double x:Key="NavigationViewItemChevronSize">12</system:Double>
<Thickness x:Key="PaneToggleButtonThickness">1,1,1,1</Thickness>



<converters:BackButtonVisibilityToVisibilityConverter x:Key="BackButtonVisibilityToVisibilityConverter" />
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
Expand Down
2 changes: 1 addition & 1 deletion src/Wpf.Ui/Controls/TextBlock/TextBlock.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<!-- The Display option causes a large aliasing effect -->
<!--<Setter Property="TextOptions.TextFormattingMode" Value="Ideal" />-->
<Setter Property="Background" Value="Transparent" />
<Setter Property="FontSize" Value="14" />
<!--<Setter Property="FontSize" Value="14" />-->
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="Focusable" Value="False" />
Expand Down
38 changes: 38 additions & 0 deletions src/Wpf.Ui/Markup/DrawingBrushIconExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Windows.Markup;
using Wpf.Ui.Controls;

namespace Wpf.Ui.Markup;

[ContentProperty(nameof(Icon))]
[MarkupExtensionReturnType(typeof(DrawingBrushIcon))]
public class DrawingBrushIconExtension : MarkupExtension
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

public DrawingBrushIconExtension(DrawingBrush icon)
{
Icon = icon;
}

public DrawingBrushIconExtension(DrawingBrush icon, double size)
: this(icon)
{
Size = size;
}

[ConstructorArgument("icon")]
public DrawingBrush Icon { get; set; }

[ConstructorArgument("size")]
public double Size { get; set; } = 16;

public override object ProvideValue(IServiceProvider serviceProvider)
{
var drawingBrushIcon = new DrawingBrushIcon { Icon = Icon, Size = Size };

return drawingBrushIcon;
}
}