Skip to content

Commit

Permalink
Added RibbonProperties.CustomIconSize
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Dec 27, 2023
1 parent def513f commit b23b75a
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 28 additions & 1 deletion Fluent.Ribbon/AttachedProperties/RibbonProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public static bool GetIsElementInQuickAccessToolBar(DependencyObject element)

#endregion IsElementInQuickAccessToolBarProperty

#region DesiredIconSize
#region IconSize

#pragma warning disable WPF0010
/// <summary>
Expand All @@ -352,4 +352,31 @@ public static IconSize GetIconSize(DependencyObject element)
}

#endregion

#region CustomIconSize

#pragma warning disable WPF0010
/// <summary>
/// Defines the custom icon size for the element.
/// </summary>
public static readonly DependencyProperty CustomIconSizeProperty = DependencyProperty.RegisterAttached(
"CustomIconSize", typeof(Size), typeof(RibbonProperties), new PropertyMetadata(default(Size)));
#pragma warning restore WPF0010

/// <summary>Helper for setting <see cref="CustomIconSizeProperty"/> on <paramref name="element"/>.</summary>
public static void SetCustomIconSize(DependencyObject element, Size value)
{
element.SetValue(CustomIconSizeProperty, value);
}

/// <summary>Helper for getting <see cref="CustomIconSizeProperty"/> from <paramref name="element"/>.</summary>
[AttachedPropertyBrowsableForType(typeof(IRibbonControl))]
[AttachedPropertyBrowsableForType(typeof(IMediumIconProvider))]
[AttachedPropertyBrowsableForType(typeof(ILargeIconProvider))]
public static Size GetCustomIconSize(DependencyObject element)
{
return (Size)element.GetValue(CustomIconSizeProperty);
}

#endregion
}
6 changes: 6 additions & 0 deletions Fluent.Ribbon/Themes/Controls/ApplicationMenuItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}" />
</Grid>
<ControlTemplate.Triggers>
Expand Down Expand Up @@ -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}}" />
<Path x:Name="path"
Grid.Column="3"
Expand Down Expand Up @@ -484,6 +486,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}}" />
<Path x:Name="path"
Grid.Column="3"
Expand Down Expand Up @@ -696,6 +699,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}}" />
</Grid>
<ControlTemplate.Triggers>
Expand Down Expand Up @@ -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}}" />
<Path x:Name="path"
Grid.Column="3"
Expand Down Expand Up @@ -1063,6 +1068,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}}" />
<Path x:Name="path"
Grid.Column="3"
Expand Down
1 change: 1 addition & 0 deletions Fluent.Ribbon/Themes/Controls/BackstageTabControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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}}" />

<ContentControl x:Name="controlLabel"
Expand Down
1 change: 1 addition & 0 deletions Fluent.Ribbon/Themes/Controls/BackstageTabItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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}}" />

<ContentControl x:Name="PART_Header"
Expand Down
2 changes: 2 additions & 0 deletions Fluent.Ribbon/Themes/Controls/Button.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<Fluent:IconPresenter x:Name="iconImage"
Margin="0 2 0 0"
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}}" />
Expand Down Expand Up @@ -141,6 +142,7 @@
VerticalAlignment="Center">
<Fluent:IconPresenter x:Name="iconImage"
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}}" />
Expand Down
3 changes: 2 additions & 1 deletion Fluent.Ribbon/Themes/Controls/CheckBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@
VerticalAlignment="Center"
Visibility="Collapsed">
<Fluent:IconPresenter x:Name="iconImage"
IconSize="{TemplateBinding Fluent:RibbonProperties.IconSize}"
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}}" />
Expand Down
1 change: 1 addition & 0 deletions Fluent.Ribbon/Themes/Controls/ComboBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}" />

Expand Down
2 changes: 2 additions & 0 deletions Fluent.Ribbon/Themes/Controls/DropDownButton.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}" />
Expand Down Expand Up @@ -223,6 +224,7 @@
VerticalAlignment="Center">
<Fluent:IconPresenter x:Name="iconImage"
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}}" />
Expand Down
2 changes: 2 additions & 0 deletions Fluent.Ribbon/Themes/Controls/InRibbonGallery.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}" />
Expand Down Expand Up @@ -173,6 +174,7 @@
VerticalAlignment="Center">
<Fluent:IconPresenter x:Name="iconImage"
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}}" />
Expand Down
4 changes: 4 additions & 0 deletions Fluent.Ribbon/Themes/Controls/MenuItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}" />
</Border>
<Image x:Name="checkedImage"
Expand Down Expand Up @@ -136,6 +137,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}}" />
</Border>
<Image x:Name="checkedImage"
Expand Down Expand Up @@ -275,6 +277,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}}" />
</Border>
<Image x:Name="checkedImage"
Expand Down Expand Up @@ -407,6 +410,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}}" />
</Border>
<Image x:Name="checkedImage"
Expand Down
3 changes: 2 additions & 1 deletion Fluent.Ribbon/Themes/Controls/RadioButton.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
VerticalAlignment="Center"
Visibility="Collapsed">
<Fluent:IconPresenter x:Name="iconImage"
IconSize="{TemplateBinding Fluent:RibbonProperties.IconSize}"
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}}" />
Expand Down
2 changes: 2 additions & 0 deletions Fluent.Ribbon/Themes/Controls/RibbonGroupBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@
BorderThickness="1">
<Fluent:IconPresenter x:Name="iconImage"
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}}" />
</Border>
Expand Down Expand Up @@ -530,6 +531,7 @@
IsHitTestVisible="False">
<Fluent:IconPresenter x:Name="iconImage"
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}}" />
<Border Margin="0"
Expand Down
1 change: 1 addition & 0 deletions Fluent.Ribbon/Themes/Controls/RibbonTabControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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}}" />
<Popup x:Name="PART_Popup"
Margin="0 0 -4 0"
Expand Down
Loading

0 comments on commit b23b75a

Please sign in to comment.