Browse Source

Fixed datacontext mismatch

flabbet 5 years ago
parent
commit
bb4dce85b9

+ 6 - 17
PixiEditor/Models/Controllers/BitmapManager.cs

@@ -42,8 +42,6 @@ namespace PixiEditor.Models.Controllers
 
 
         public Layer ActiveLayer => ActiveDocument.ActiveLayer;
         public Layer ActiveLayer => ActiveDocument.ActiveLayer;
 
 
-        public int ActiveLayerIndex => ActiveDocument.ActiveLayerIndex;
-
         public Color PrimaryColor { get; set; }
         public Color PrimaryColor { get; set; }
 
 
         public int ToolSize => SelectedTool.Toolbar.GetSetting("ToolSize") != null ? (int)SelectedTool.Toolbar.GetSetting("ToolSize").Value : 1;
         public int ToolSize => SelectedTool.Toolbar.GetSetting("ToolSize") != null ? (int)SelectedTool.Toolbar.GetSetting("ToolSize").Value : 1;
@@ -54,7 +52,7 @@ namespace PixiEditor.Models.Controllers
         public BitmapOperationsUtility BitmapOperations { get; set; }
         public BitmapOperationsUtility BitmapOperations { get; set; }
         public ReadonlyToolUtility ReadonlyToolUtility { get; set; }
         public ReadonlyToolUtility ReadonlyToolUtility { get; set; }
 
 
-        private Document _activeDocument = null;
+        private Document _activeDocument;
         public Document ActiveDocument
         public Document ActiveDocument
         {
         {
             get => _activeDocument;
             get => _activeDocument;
@@ -68,14 +66,8 @@ namespace PixiEditor.Models.Controllers
 
 
         public void SetActiveTool(Tool tool)
         public void SetActiveTool(Tool tool)
         {
         {
-            if (PreviewLayer != null)
-            {
-                PreviewLayer.Clear();
-            }
-            if (SelectedTool != null)
-            {
-                SelectedTool.Toolbar.SaveToolbarSettings();
-            }
+            PreviewLayer?.Clear();
+            SelectedTool?.Toolbar.SaveToolbarSettings();
             SelectedTool = tool;
             SelectedTool = tool;
             SelectedTool.Toolbar.LoadSharedSettings();
             SelectedTool.Toolbar.LoadSharedSettings();
         }
         }
@@ -150,16 +142,13 @@ namespace PixiEditor.Models.Controllers
         private void MouseController_StartedRecordingChanges(object sender, EventArgs e)
         private void MouseController_StartedRecordingChanges(object sender, EventArgs e)
         {
         {
             SelectedTool.OnMouseDown();
             SelectedTool.OnMouseDown();
-            if (PreviewLayer != null)
-            {
-                PreviewLayer.Clear();
-            }
+            PreviewLayer?.Clear();
         }
         }
 
 
         private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
         private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
         {
         {
             SelectedTool.OnMouseUp();
             SelectedTool.OnMouseUp();
-            if (IsOperationTool(SelectedTool) && (SelectedTool as BitmapOperationTool).RequiresPreviewLayer)
+            if (IsOperationTool(SelectedTool) && ((BitmapOperationTool) SelectedTool).RequiresPreviewLayer)
             {
             {
                 BitmapOperations.StopAction();
                 BitmapOperations.StopAction();
             }
             }
@@ -196,7 +185,7 @@ namespace PixiEditor.Models.Controllers
 
 
         public static bool IsOperationTool(Tool tool)
         public static bool IsOperationTool(Tool tool)
         {
         {
-            return typeof(BitmapOperationTool).IsAssignableFrom(tool.GetType());
+            return tool is BitmapOperationTool;
         }
         }
 
 
     }
     }

+ 2 - 4
PixiEditor/Views/MainWindow.xaml.cs

@@ -14,10 +14,8 @@ namespace PixiEditor
         {
         {
             InitializeComponent();
             InitializeComponent();
             StateChanged += MainWindowStateChangeRaised;
             StateChanged += MainWindowStateChangeRaised;
-            MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
-            ViewModelMain vm = new ViewModelMain();
-            vm.CloseAction = new Action(Close);
-            DataContext = vm;
+            MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
+            ((ViewModelMain)DataContext).CloseAction = Close;
         }
         }
 
 
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
         private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)