-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Fixed issue where icons were not displayed on submenus of shell …
…extensions (#14070)
- Loading branch information
1 parent
237dca7
commit 7eb7437
Showing
4 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
src/Files.App/ResourceDictionaries/MenuFlyoutSubItemWithImageStyle.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<!-- Copyright (c) 2023 Files Community. Licensed under the MIT License. See the LICENSE. --> | ||
<ResourceDictionary | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:menus="using:Files.App.UserControls.Menus"> | ||
|
||
<Style x:Key="MenuFlyoutSubItemWithImageStyle" TargetType="MenuFlyoutSubItem"> | ||
<Setter Property="Padding" Value="{ThemeResource MenuFlyoutItemThemePadding}" /> | ||
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" /> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate TargetType="MenuFlyoutSubItem"> | ||
|
||
<Grid | ||
x:Name="LayoutRoot" | ||
Margin="{StaticResource MenuFlyoutItemMargin}" | ||
Padding="{TemplateBinding Padding}" | ||
Background="{TemplateBinding Background}" | ||
BorderBrush="{TemplateBinding BorderBrush}" | ||
BorderThickness="{TemplateBinding BorderThickness}" | ||
CornerRadius="{TemplateBinding CornerRadius}"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<Viewbox | ||
x:Name="IconRoot" | ||
Grid.Column="0" | ||
Width="16" | ||
Height="16" | ||
HorizontalAlignment="Left" | ||
VerticalAlignment="Center" | ||
Visibility="Collapsed"> | ||
<ContentPresenter x:Name="IconContent" Content="{TemplateBinding Icon}" /> | ||
</Viewbox> | ||
|
||
<Image | ||
Grid.Column="0" | ||
Width="16" | ||
Height="16" | ||
Margin="0" | ||
HorizontalAlignment="Left" | ||
VerticalAlignment="Center" | ||
Source="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=(menus:MenuFlyoutSubItemCustomProperties.BitmapIcon)}" | ||
Stretch="Uniform" /> | ||
|
||
<TextBlock | ||
x:Name="TextBlock" | ||
Grid.Column="0" | ||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" | ||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" | ||
Foreground="{TemplateBinding Foreground}" | ||
Text="{TemplateBinding Text}" | ||
TextTrimming="Clip" /> | ||
|
||
<FontIcon | ||
x:Name="SubItemChevron" | ||
Grid.Column="1" | ||
Margin="{StaticResource MenuFlyoutItemChevronMargin}" | ||
AutomationProperties.AccessibilityView="Raw" | ||
FontFamily="{ThemeResource SymbolThemeFontFamily}" | ||
FontSize="12" | ||
Foreground="{ThemeResource MenuFlyoutSubItemChevron}" | ||
Glyph="" | ||
MirroredWhenRightToLeft="True" /> | ||
</Grid> | ||
|
||
<VisualStateManager.VisualStateGroups> | ||
<VisualStateGroup x:Name="CommonStates"> | ||
<VisualState x:Name="Normal" /> | ||
<VisualState x:Name="PointerOver"> | ||
<VisualState.Setters> | ||
<Setter Target="LayoutRoot.Background" Value="{ThemeResource MenuFlyoutSubItemBackgroundPointerOver}" /> | ||
<Setter Target="TextBlock.Foreground" Value="{ThemeResource MenuFlyoutSubItemForegroundPointerOver}" /> | ||
<Setter Target="SubItemChevron.Foreground" Value="{ThemeResource MenuFlyoutSubItemChevronPointerOver}" /> | ||
<Setter Target="IconContent.Foreground" Value="{ThemeResource MenuFlyoutSubItemForegroundPointerOver}" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
<VisualState x:Name="Pressed"> | ||
<VisualState.Setters> | ||
<Setter Target="LayoutRoot.Background" Value="{ThemeResource MenuFlyoutSubItemBackgroundPressed}" /> | ||
<Setter Target="TextBlock.Foreground" Value="{ThemeResource MenuFlyoutSubItemForegroundPressed}" /> | ||
<Setter Target="SubItemChevron.Foreground" Value="{ThemeResource MenuFlyoutSubItemChevronPressed}" /> | ||
<Setter Target="IconContent.Foreground" Value="{ThemeResource MenuFlyoutSubItemForegroundPressed}" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
<VisualState x:Name="SubMenuOpened"> | ||
<VisualState.Setters> | ||
<Setter Target="LayoutRoot.Background" Value="{ThemeResource MenuFlyoutSubItemBackgroundSubMenuOpened}" /> | ||
<Setter Target="TextBlock.Foreground" Value="{ThemeResource MenuFlyoutSubItemForegroundSubMenuOpened}" /> | ||
<Setter Target="SubItemChevron.Foreground" Value="{ThemeResource MenuFlyoutSubItemChevronSubMenuOpened}" /> | ||
<Setter Target="IconContent.Foreground" Value="{ThemeResource MenuFlyoutSubItemForegroundSubMenuOpened}" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
<VisualState x:Name="Disabled"> | ||
<VisualState.Setters> | ||
<Setter Target="LayoutRoot.Background" Value="{ThemeResource MenuFlyoutSubItemBackgroundDisabled}" /> | ||
<Setter Target="TextBlock.Foreground" Value="{ThemeResource MenuFlyoutSubItemForegroundDisabled}" /> | ||
<Setter Target="SubItemChevron.Foreground" Value="{ThemeResource MenuFlyoutSubItemChevronDisabled}" /> | ||
<Setter Target="IconContent.Foreground" Value="{ThemeResource MenuFlyoutSubItemForegroundDisabled}" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
</VisualStateGroup> | ||
<VisualStateGroup x:Name="CheckPlaceholderStates"> | ||
<VisualState x:Name="NoPlaceholder" /> | ||
<VisualState x:Name="CheckPlaceholder"> | ||
<VisualState.Setters> | ||
<Setter Target="TextBlock.Margin" Value="{ThemeResource MenuFlyoutItemPlaceholderThemeThickness}" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
<VisualState x:Name="IconPlaceholder"> | ||
<VisualState.Setters> | ||
<Setter Target="TextBlock.Margin" Value="{ThemeResource MenuFlyoutItemPlaceholderThemeThickness}" /> | ||
<Setter Target="IconRoot.Visibility" Value="Visible" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
<VisualState x:Name="CheckAndIconPlaceholder"> | ||
<VisualState.Setters> | ||
<Setter Target="TextBlock.Margin" Value="{ThemeResource MenuFlyoutItemDoublePlaceholderThemeThickness}" /> | ||
<Setter Target="IconRoot.Margin" Value="{ThemeResource MenuFlyoutItemPlaceholderThemeThickness}" /> | ||
<Setter Target="IconRoot.Visibility" Value="Visible" /> | ||
</VisualState.Setters> | ||
</VisualState> | ||
</VisualStateGroup> | ||
<VisualStateGroup x:Name="PaddingSizeStates"> | ||
<VisualState x:Name="DefaultPadding" /> | ||
<VisualState x:Name="NarrowPadding"> | ||
<Storyboard> | ||
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Padding"> | ||
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource MenuFlyoutItemThemePaddingNarrow}" /> | ||
</ObjectAnimationUsingKeyFrames> | ||
</Storyboard> | ||
</VisualState> | ||
</VisualStateGroup> | ||
</VisualStateManager.VisualStateGroups> | ||
</Grid> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</ResourceDictionary> |
31 changes: 31 additions & 0 deletions
31
src/Files.App/UserControls/Menus/MenuFlyoutSubItemCustomProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Media.Imaging; | ||
|
||
namespace Files.App.UserControls.Menus | ||
{ | ||
[Microsoft.UI.Xaml.Data.Bindable] | ||
public class MenuFlyoutSubItemCustomProperties : DependencyObject | ||
{ | ||
public static readonly DependencyProperty BitmapIconProperty = | ||
DependencyProperty.Register("BitmapIcon", typeof(BitmapImage), typeof(MenuFlyoutSubItemCustomProperties), new PropertyMetadata(null, OnBitmapIconChanged)); | ||
|
||
public static BitmapImage GetBitmapIcon(DependencyObject obj) | ||
{ | ||
return (BitmapImage)obj.GetValue(BitmapIconProperty); | ||
} | ||
|
||
public static void SetBitmapIcon(DependencyObject obj, BitmapImage value) | ||
{ | ||
obj.SetValue(BitmapIconProperty, value); | ||
} | ||
|
||
private static void OnBitmapIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
(d as MenuFlyoutSubItem).Icon = e.NewValue is not null ? new IconSourceElement() : null; | ||
} | ||
} | ||
} |