Browse Source

Maybe reduce design time command errors

Equbuxu 3 years ago
parent
commit
9e8c00f6fe

+ 5 - 6
src/PixiEditor/Models/Commands/XAML/Command.cs

@@ -1,7 +1,6 @@
 using System.Windows.Input;
 using System.Windows.Input;
 using System.Windows.Markup;
 using System.Windows.Markup;
 using PixiEditor.Helpers;
 using PixiEditor.Helpers;
-using PixiEditor.ViewModels;
 
 
 namespace PixiEditor.Models.Commands.XAML;
 namespace PixiEditor.Models.Commands.XAML;
 
 
@@ -21,11 +20,6 @@ internal class Command : MarkupExtension
 
 
     public override object ProvideValue(IServiceProvider serviceProvider)
     public override object ProvideValue(IServiceProvider serviceProvider)
     {
     {
-        if (commandController == null)
-        {
-            commandController = ViewModelMain.Current.CommandController;
-        }
-
         if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
         if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
         {
         {
             var attribute = DesignCommandHelpers.GetCommandAttribute(Name);
             var attribute = DesignCommandHelpers.GetCommandAttribute(Name);
@@ -40,6 +34,11 @@ internal class Command : MarkupExtension
                 }, false);
                 }, false);
         }
         }
 
 
+        if (commandController is null)
+        {
+            commandController = ViewModelMain.Current.CommandController;
+        }
+
         var command = commandController.Commands[Name];
         var command = commandController.Commands[Name];
         return GetPixiCommand ? command : GetICommand(command, UseProvided);
         return GetPixiCommand ? command : GetICommand(command, UseProvided);
     }
     }

+ 6 - 7
src/PixiEditor/Models/Commands/XAML/ShortcutBinding.cs

@@ -2,7 +2,6 @@
 using System.Windows.Markup;
 using System.Windows.Markup;
 using PixiEditor.Helpers;
 using PixiEditor.Helpers;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.DataHolders;
-using PixiEditor.ViewModels;
 using ActualCommand = PixiEditor.Models.Commands.Commands.Command;
 using ActualCommand = PixiEditor.Models.Commands.Commands.Command;
 
 
 namespace PixiEditor.Models.Commands.XAML;
 namespace PixiEditor.Models.Commands.XAML;
@@ -19,17 +18,17 @@ internal class ShortcutBinding : MarkupExtension
 
 
     public override object ProvideValue(IServiceProvider serviceProvider)
     public override object ProvideValue(IServiceProvider serviceProvider)
     {
     {
+        //if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
+        //{
+        var attribute = DesignCommandHelpers.GetCommandAttribute(Name);
+        return new KeyCombination(attribute.Key, attribute.Modifiers).ToString();
+        //}
+
         if (commandController == null)
         if (commandController == null)
         {
         {
             commandController = ViewModelMain.Current.CommandController;
             commandController = ViewModelMain.Current.CommandController;
         }
         }
 
 
-        if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
-        {
-            var attribute = DesignCommandHelpers.GetCommandAttribute(Name);
-            return new KeyCombination(attribute.Key, attribute.Modifiers).ToString();
-        }
-
         return GetBinding(commandController.Commands[Name]).ProvideValue(serviceProvider);
         return GetBinding(commandController.Commands[Name]).ProvideValue(serviceProvider);
     }
     }