Browse Source

Fix for : If you change percentage, for example to 50%, unfocus and then change to 100% it doesn't come back to original width/height.

tomaszkot 3 years ago
parent
commit
665a56f8f1

+ 1 - 1
PixiEditor/Views/UserControls/SizePicker.xaml

@@ -7,7 +7,7 @@
              xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
              xmlns:enums="clr-namespace:PixiEditor.Models.Enums"
              mc:Ignorable="d"
-             d:DesignHeight="220" d:DesignWidth="300" Name="uc">
+             d:DesignHeight="220" d:DesignWidth="300" Name="uc" Loaded="OnLoad">
     <UserControl.Resources>
         <Style TargetType="local:SizeInput">
             <Setter Property="HorizontalAlignment" Value="Left"/>

+ 10 - 2
PixiEditor/Views/UserControls/SizePicker.xaml.cs

@@ -32,21 +32,29 @@ namespace PixiEditor.Views
         public static readonly DependencyProperty SizeUnitSelectionVisibilityProperty =
             DependencyProperty.Register(nameof(SizeUnitSelectionVisibility), typeof(Visibility), typeof(SizePicker), new PropertyMetadata(Visibility.Collapsed));
 
+        System.Drawing.Size? initSize = null;
 
         public SizePicker()
         {
             InitializeComponent();
 
             EnableSizeEditors();
+        }
 
+        void OnLoad(object sender, RoutedEventArgs e)
+        {
+            var sizePicker = sender as SizePicker;
+            sizePicker.initSize = new System.Drawing.Size(sizePicker.ChosenWidth, sizePicker.ChosenHeight);
         }
 
         private static void InputSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
             var sizePicker = d as SizePicker;
-            
+            if (!sizePicker.initSize.HasValue)
+                return;
+
             var newValue = (int)e.NewValue;
-            var newSize = SizeCalculator.CalcAbsoluteFromPercentage(newValue, new System.Drawing.Size(sizePicker.ChosenWidth, sizePicker.ChosenHeight));
+            var newSize = SizeCalculator.CalcAbsoluteFromPercentage(newValue, sizePicker.initSize.Value);
             if (newSize.Width > sizePicker.MaxWidth || newSize.Width > sizePicker.MaxHeight)
             {
                 newSize = new System.Drawing.Size(newSize.Width, newSize.Height);