Browse Source

Use command icons in main menu

CPKreuz 2 years ago
parent
commit
c09c4932be

+ 16 - 0
src/PixiEditor/Models/Commands/XAML/Menu.cs

@@ -35,7 +35,23 @@ internal class Menu : System.Windows.Controls.Menu
 
         var command = CommandController.Current.Commands[value];
 
+        var icon = new Image 
+        { 
+            Source = command.GetIcon(), 
+            Width = 20, Height = 20,
+            Opacity = command.CanExecute() ? 1 : 0.75
+        };
+        
+        icon.IsVisibleChanged += (_, v) =>
+        {
+            if ((bool)v.NewValue)
+            {
+                icon.Opacity = command.CanExecute() ? 1 : 0.75;
+            }
+        };
+
         item.Command = Command.GetICommand(command, false);
+        item.Icon = icon;
         item.SetBinding(MenuItem.InputGestureTextProperty, ShortcutBinding.GetBinding(command));
     }
 

+ 2 - 2
src/PixiEditor/Styles/MenuButtonStyle.xaml

@@ -27,13 +27,13 @@
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="{x:Type MenuItem}">
-                    <Border x:Name="Border" Padding="2.5"
+                    <Border x:Name="Border" Padding="2.5,1,2.5,1"
                             Background="Transparent"
                             BorderBrush="{TemplateBinding BorderBrush}"
                             BorderThickness="0">
                         <Grid>
                             <Grid.ColumnDefinitions>
-                                <ColumnDefinition x:Name="Col0" MinWidth="17" Width="Auto"
+                                <ColumnDefinition x:Name="Col0" Width="Auto" MinWidth="5"
                                                   SharedSizeGroup="MenuItemIconColumnGroup" />
                                 <ColumnDefinition Width="Auto" SharedSizeGroup="MenuTextColumnGroup" />
                                 <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIGTColumnGroup" />