From b23b75a7744639257f7d0cd8b1cf378fb1e0dffc Mon Sep 17 00:00:00 2001 From: Bastian Schmidt Date: Wed, 27 Dec 2023 09:53:31 +0100 Subject: [PATCH] Added `RibbonProperties.CustomIconSize` --- Changelog.md | 1 + .../AttachedProperties/RibbonProperties.cs | 29 ++++++++++++++++++- .../Themes/Controls/ApplicationMenuItem.xaml | 6 ++++ .../Themes/Controls/BackstageTabControl.xaml | 1 + .../Themes/Controls/BackstageTabItem.xaml | 1 + Fluent.Ribbon/Themes/Controls/Button.xaml | 2 ++ Fluent.Ribbon/Themes/Controls/CheckBox.xaml | 3 +- Fluent.Ribbon/Themes/Controls/ComboBox.xaml | 1 + .../Themes/Controls/DropDownButton.xaml | 2 ++ .../Themes/Controls/InRibbonGallery.xaml | 2 ++ Fluent.Ribbon/Themes/Controls/MenuItem.xaml | 4 +++ .../Themes/Controls/RadioButton.xaml | 3 +- .../Themes/Controls/RibbonGroupBox.xaml | 2 ++ .../Themes/Controls/RibbonTabControl.xaml | 1 + .../Themes/Controls/RibbonTextBox.xaml | 4 ++- Fluent.Ribbon/Themes/Controls/Spinner.xaml | 2 ++ .../Themes/Controls/SplitButton.xaml | 2 ++ .../Themes/Controls/ToggleButton.xaml | 2 ++ 18 files changed, 64 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index 35d1b056f..79aeb3379 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,6 +13,7 @@ - Performance of measuring (and thus rendering) of `RibbonTabItem` (and it's contents) was improved by reducing the amount of measures required. Most of the time there should only be one or two measure calls when switching tabs, compared to six or eight in case of the showcase application. This is mostly achieved by getting rid of internal caching. The caching turned out to be more expensive than not caching at all. + - Added `RibbonProperties.CustomIconSize` as an attached property. This is used inside control templates to set `CustomSize` of `IconPresenter`. - [#1177](../../issues/1177) - RibbonComboBox cannot be customized based on the original RibbonComboBox style (thanks @nishy2000) - [#1180](../../issues/1180) - Padding and BorderBrush of the gallery control do not work (thanks @nishy2000) diff --git a/Fluent.Ribbon/AttachedProperties/RibbonProperties.cs b/Fluent.Ribbon/AttachedProperties/RibbonProperties.cs index 83649984d..81b71b026 100644 --- a/Fluent.Ribbon/AttachedProperties/RibbonProperties.cs +++ b/Fluent.Ribbon/AttachedProperties/RibbonProperties.cs @@ -326,7 +326,7 @@ public static bool GetIsElementInQuickAccessToolBar(DependencyObject element) #endregion IsElementInQuickAccessToolBarProperty - #region DesiredIconSize + #region IconSize #pragma warning disable WPF0010 /// @@ -352,4 +352,31 @@ public static IconSize GetIconSize(DependencyObject element) } #endregion + + #region CustomIconSize + +#pragma warning disable WPF0010 + /// + /// Defines the custom icon size for the element. + /// + public static readonly DependencyProperty CustomIconSizeProperty = DependencyProperty.RegisterAttached( + "CustomIconSize", typeof(Size), typeof(RibbonProperties), new PropertyMetadata(default(Size))); +#pragma warning restore WPF0010 + + /// Helper for setting on . + public static void SetCustomIconSize(DependencyObject element, Size value) + { + element.SetValue(CustomIconSizeProperty, value); + } + + /// Helper for getting from . + [AttachedPropertyBrowsableForType(typeof(IRibbonControl))] + [AttachedPropertyBrowsableForType(typeof(IMediumIconProvider))] + [AttachedPropertyBrowsableForType(typeof(ILargeIconProvider))] + public static Size GetCustomIconSize(DependencyObject element) + { + return (Size)element.GetValue(CustomIconSizeProperty); + } + + #endregion } \ No newline at end of file diff --git a/Fluent.Ribbon/Themes/Controls/ApplicationMenuItem.xaml b/Fluent.Ribbon/Themes/Controls/ApplicationMenuItem.xaml index 83730a83b..72c07e757 100644 --- a/Fluent.Ribbon/Themes/Controls/ApplicationMenuItem.xaml +++ b/Fluent.Ribbon/Themes/Controls/ApplicationMenuItem.xaml @@ -87,6 +87,7 @@ HorizontalAlignment="Center" VerticalAlignment="Top" IconSize="{Binding Path=(Fluent:RibbonProperties.IconSize), RelativeSource={RelativeSource TemplatedParent}}" + CustomSize="{Binding Path=(Fluent:RibbonProperties.CustomIconSize), RelativeSource={RelativeSource TemplatedParent}}" LargeIcon="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" /> @@ -195,6 +196,7 @@ HorizontalAlignment="Center" VerticalAlignment="Top" IconSize="{Binding Path=(Fluent:RibbonProperties.IconSize), RelativeSource={RelativeSource TemplatedParent}}" + CustomSize="{Binding Path=(Fluent:RibbonProperties.CustomIconSize), RelativeSource={RelativeSource TemplatedParent}}" LargeIcon="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" /> @@ -792,6 +796,7 @@ HorizontalAlignment="Center" VerticalAlignment="Top" IconSize="{Binding Path=(Fluent:RibbonProperties.IconSize), RelativeSource={RelativeSource TemplatedParent}}" + CustomSize="{Binding Path=(Fluent:RibbonProperties.CustomIconSize), RelativeSource={RelativeSource TemplatedParent}}" LargeIcon="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" /> @@ -141,6 +142,7 @@ VerticalAlignment="Center"> diff --git a/Fluent.Ribbon/Themes/Controls/CheckBox.xaml b/Fluent.Ribbon/Themes/Controls/CheckBox.xaml index ac4dce3c9..3fe6385ee 100644 --- a/Fluent.Ribbon/Themes/Controls/CheckBox.xaml +++ b/Fluent.Ribbon/Themes/Controls/CheckBox.xaml @@ -135,7 +135,8 @@ VerticalAlignment="Center" Visibility="Collapsed"> diff --git a/Fluent.Ribbon/Themes/Controls/ComboBox.xaml b/Fluent.Ribbon/Themes/Controls/ComboBox.xaml index ff0e3d5be..b50c4d26e 100644 --- a/Fluent.Ribbon/Themes/Controls/ComboBox.xaml +++ b/Fluent.Ribbon/Themes/Controls/ComboBox.xaml @@ -89,6 +89,7 @@ Margin="3 0 0 0" VerticalAlignment="Center" IconSize="{Binding Path=(Fluent:RibbonProperties.IconSize), RelativeSource={RelativeSource TemplatedParent}}" + CustomSize="{Binding Path=(Fluent:RibbonProperties.CustomIconSize), RelativeSource={RelativeSource TemplatedParent}}" MediumIcon="{Binding MediumIcon, RelativeSource={RelativeSource TemplatedParent}}" SmallIcon="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" /> diff --git a/Fluent.Ribbon/Themes/Controls/DropDownButton.xaml b/Fluent.Ribbon/Themes/Controls/DropDownButton.xaml index 014ece916..2ade71e0a 100644 --- a/Fluent.Ribbon/Themes/Controls/DropDownButton.xaml +++ b/Fluent.Ribbon/Themes/Controls/DropDownButton.xaml @@ -117,6 +117,7 @@ HorizontalAlignment="Center" VerticalAlignment="Center" IconSize="{Binding Path=(Fluent:RibbonProperties.IconSize), RelativeSource={RelativeSource TemplatedParent}}" + CustomSize="{Binding Path=(Fluent:RibbonProperties.CustomIconSize), RelativeSource={RelativeSource TemplatedParent}}" LargeIcon="{Binding LargeIcon, RelativeSource={RelativeSource TemplatedParent}}" MediumIcon="{Binding MediumIcon, RelativeSource={RelativeSource TemplatedParent}}" SmallIcon="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" /> @@ -223,6 +224,7 @@ VerticalAlignment="Center"> diff --git a/Fluent.Ribbon/Themes/Controls/InRibbonGallery.xaml b/Fluent.Ribbon/Themes/Controls/InRibbonGallery.xaml index 07de2e850..18c5ded83 100644 --- a/Fluent.Ribbon/Themes/Controls/InRibbonGallery.xaml +++ b/Fluent.Ribbon/Themes/Controls/InRibbonGallery.xaml @@ -97,6 +97,7 @@ HorizontalAlignment="Center" VerticalAlignment="Center" IconSize="{Binding Path=(Fluent:RibbonProperties.IconSize), RelativeSource={RelativeSource TemplatedParent}}" + CustomSize="{Binding Path=(Fluent:RibbonProperties.CustomIconSize), RelativeSource={RelativeSource TemplatedParent}}" LargeIcon="{Binding LargeIcon, RelativeSource={RelativeSource TemplatedParent}}" MediumIcon="{Binding MediumIcon, RelativeSource={RelativeSource TemplatedParent}}" SmallIcon="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" /> @@ -173,6 +174,7 @@ VerticalAlignment="Center"> diff --git a/Fluent.Ribbon/Themes/Controls/MenuItem.xaml b/Fluent.Ribbon/Themes/Controls/MenuItem.xaml index 692519f7f..d4f179a43 100644 --- a/Fluent.Ribbon/Themes/Controls/MenuItem.xaml +++ b/Fluent.Ribbon/Themes/Controls/MenuItem.xaml @@ -42,6 +42,7 @@ HorizontalAlignment="Center" VerticalAlignment="Center" IconSize="{Binding Path=(Fluent:RibbonProperties.IconSize), RelativeSource={RelativeSource TemplatedParent}}" + CustomSize="{Binding Path=(Fluent:RibbonProperties.CustomIconSize), RelativeSource={RelativeSource TemplatedParent}}" SmallIcon="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" /> diff --git a/Fluent.Ribbon/Themes/Controls/RibbonGroupBox.xaml b/Fluent.Ribbon/Themes/Controls/RibbonGroupBox.xaml index 0b2e3a52b..3cb504012 100644 --- a/Fluent.Ribbon/Themes/Controls/RibbonGroupBox.xaml +++ b/Fluent.Ribbon/Themes/Controls/RibbonGroupBox.xaml @@ -367,6 +367,7 @@ BorderThickness="1"> @@ -530,6 +531,7 @@ IsHitTestVisible="False"> @@ -106,7 +107,8 @@ diff --git a/Fluent.Ribbon/Themes/Controls/Spinner.xaml b/Fluent.Ribbon/Themes/Controls/Spinner.xaml index 62febc866..6d3190577 100644 --- a/Fluent.Ribbon/Themes/Controls/Spinner.xaml +++ b/Fluent.Ribbon/Themes/Controls/Spinner.xaml @@ -64,6 +64,7 @@ Margin="4 0 0 0" VerticalAlignment="Center" IconSize="{Binding Path=(Fluent:RibbonProperties.IconSize), RelativeSource={RelativeSource TemplatedParent}}" + CustomSize="{Binding Path=(Fluent:RibbonProperties.CustomIconSize), RelativeSource={RelativeSource TemplatedParent}}" MediumIcon="{Binding MediumIcon, RelativeSource={RelativeSource TemplatedParent}}" SmallIcon="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" /> @@ -238,6 +239,7 @@ Margin="0 0 4 0" VerticalAlignment="Center" IconSize="{Binding Path=(Fluent:RibbonProperties.IconSize), RelativeSource={RelativeSource TemplatedParent}}" + CustomSize="{Binding Path=(Fluent:RibbonProperties.CustomIconSize), RelativeSource={RelativeSource TemplatedParent}}" MediumIcon="{Binding MediumIcon, RelativeSource={RelativeSource TemplatedParent}}" SmallIcon="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" /> diff --git a/Fluent.Ribbon/Themes/Controls/SplitButton.xaml b/Fluent.Ribbon/Themes/Controls/SplitButton.xaml index 1f87b3a9f..43747f463 100644 --- a/Fluent.Ribbon/Themes/Controls/SplitButton.xaml +++ b/Fluent.Ribbon/Themes/Controls/SplitButton.xaml @@ -387,6 +387,7 @@ HorizontalAlignment="Center" VerticalAlignment="Center" IconSize="{Binding Path=(Fluent:RibbonProperties.IconSize), RelativeSource={RelativeSource TemplatedParent}}" + CustomSize="{Binding Path=(Fluent:RibbonProperties.CustomIconSize), RelativeSource={RelativeSource TemplatedParent}}" LargeIcon="{Binding LargeIcon, RelativeSource={RelativeSource TemplatedParent}}" MediumIcon="{Binding MediumIcon, RelativeSource={RelativeSource TemplatedParent}}" SmallIcon="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" /> @@ -459,6 +460,7 @@ VerticalAlignment="Center"> diff --git a/Fluent.Ribbon/Themes/Controls/ToggleButton.xaml b/Fluent.Ribbon/Themes/Controls/ToggleButton.xaml index 193e38922..a8a8a6d52 100644 --- a/Fluent.Ribbon/Themes/Controls/ToggleButton.xaml +++ b/Fluent.Ribbon/Themes/Controls/ToggleButton.xaml @@ -72,6 +72,7 @@ @@ -154,6 +155,7 @@