Quellcode durchsuchen

Added Sizing properties to DynamicEditorGridLayout

Kenric Nugteren vor 7 Monaten
Ursprung
Commit
b13a95bc61

+ 1 - 0
inabox.wpf/DynamicGrid/DynamicEditorForm/DynamicEditorForm.xaml

@@ -22,6 +22,7 @@
                              Background="White"
                              CornerRadius="0"
                              d:DesignHeight="400" d:DesignWidth="400"
+                              Loaded="ThemableChromelessWindow_Loaded"
                              >
     <syncfusion:ChromelessWindow.DataContext>
         <local:DynamicEditorFormModel />

+ 18 - 25
inabox.wpf/DynamicGrid/DynamicEditorForm/DynamicEditorForm.xaml.cs

@@ -146,25 +146,30 @@ namespace InABox.DynamicGrid
         }
 
         private void Editor_OnEditorCreated(object sender, double height, double width)
+        {
+        }
+
+        private void Window_Closing(object sender, CancelEventArgs e)
+        {
+            if (DialogResult == true)
+                Form.SaveItem(e);
+        }
+
+        private bool bChanged = false;
+        private void Form_OnOnChanged(object? sender, EventArgs e)
+        {
+            bChanged = true;
+        }
+
+        private void ThemableChromelessWindow_Loaded(object sender, RoutedEventArgs e)
         {
             var screen = WpfScreen.GetScreenFrom(new Point(Left, Top));
 
             double spareheight = 90;
             double sparewidth = 25;
 
-            var desiredheight = height;
-            var desiredwidth = width;
-            if (Form.Pages != null)
-                foreach (var page in Form.Pages)
-                {
-                    if (desiredheight < page.MinimumSize().Height)
-                        desiredheight = page.MinimumSize().Height;
-                    if (desiredwidth < page.MinimumSize().Width)
-                        desiredwidth = page.MinimumSize().Width;
-                }
-
-            desiredheight += spareheight;
-            desiredwidth += sparewidth;
+            var desiredheight = Form.ContentHeight + spareheight;
+            var desiredwidth = Form.ContentWidth + sparewidth;
 
             var maxheight = screen.WorkingArea.Height - 0;
             Height = desiredheight > maxheight ? maxheight : desiredheight;
@@ -178,17 +183,5 @@ namespace InABox.DynamicGrid
             var scaption = Form.Items[0].GetType().GetCaption();
             Title = "Edit " + scaption.SplitCamelCase();
         }
-
-        private void Window_Closing(object sender, CancelEventArgs e)
-        {
-            if (DialogResult == true)
-                Form.SaveItem(e);
-        }
-
-        private bool bChanged = false;
-        private void Form_OnOnChanged(object? sender, EventArgs e)
-        {
-            bChanged = true;
-        }
     }
 }

+ 4 - 0
inabox.wpf/DynamicGrid/DynamicEditorForm/EmbeddedDynamicEditorForm.xaml.cs

@@ -34,6 +34,7 @@ namespace InABox.DynamicGrid
             //OKButton.IsEnabled = true;
             //CancelButton.IsEnabled = true;
             OnChanged?.Invoke(this, EventArgs.Empty);
+            UpdateButtonEnabled();
         }
 
         public delegate void OKEvent();
@@ -104,6 +105,9 @@ namespace InABox.DynamicGrid
             }
         }
 
+        public double ContentWidth => Editor.TotalWidth;
+        public double ContentHeight => Editor.TotalHeight;
+
         private void UpdateButtonEnabled()
         {
             OKButton.IsEnabled = !ReadOnly && (!DisableOKIfUnchanged || bChanged);

+ 3 - 0
inabox.wpf/DynamicGrid/DynamicEditorGrid.xaml.cs

@@ -49,6 +49,9 @@ public partial class DynamicEditorGrid : UserControl, IDynamicEditorHost
         }
     }
 
+    public double TotalWidth => Layout?.TotalWidth ?? 0;
+    public double TotalHeight => Layout?.TotalHeight ?? 0;
+
     public DynamicEditorGrid()
     {
         InitializeComponent();

+ 13 - 1
inabox.wpf/DynamicGrid/Layouts/DefaultDynamicEditorGridLayout.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -17,6 +18,13 @@ namespace InABox.DynamicGrid
 
         private DynamicTabControl Details;
 
+        private double PageWidth = 0;
+        private double PageHeight = 0;
+
+        public override double TotalWidth => PageWidth;
+
+        public override double TotalHeight => PageHeight;
+
         public DefaultDynamicEditorGridLayout()
         {
             Details = new DynamicTabControl();
@@ -38,6 +46,10 @@ namespace InABox.DynamicGrid
                 tab.Header = page.Caption();
                 tab.Content = page;
                 Details.Items.Add(tab);
+
+                var minSize = page.MinimumSize();
+                PageWidth = Math.Max(PageWidth, minSize.Width);
+                PageHeight = Math.Max(PageHeight, minSize.Height);
             }
 
             Details.SelectedItem = Details.Items.Count > 0 ? Details.Items[0] : null;

+ 6 - 2
inabox.wpf/DynamicGrid/Layouts/DynamicEditorGridLayout.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -9,13 +10,16 @@ namespace InABox.DynamicGrid;
 
 public abstract class DynamicEditorGridLayout : ContentControl
 {
-
     public abstract bool TabStripVisible { get; set; }
     
     public delegate void SelectPageHandler(IDynamicEditorPage page);
 
     public event SelectPageHandler? OnSelectPage;
 
+    public abstract double TotalWidth { get; }
+
+    public abstract double TotalHeight { get; }
+
     protected void SelectPage(IDynamicEditorPage page)
     {
         OnSelectPage?.Invoke(page);

+ 17 - 3
inabox.wpf/DynamicGrid/Layouts/VerticalDynamicEditorGridLayout.xaml.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -25,7 +26,14 @@ namespace InABox.DynamicGrid
             get { return Editors.TabStripVisible; }
             set { Editors.TabStripVisible = value; }
         }
-        
+
+        private double _totalWidth;
+        public override double TotalWidth => _totalWidth;
+
+        private double _editorHeight;
+        private double _pageHeight;
+        public override double TotalHeight => _editorHeight + _pageHeight;
+
         public VerticalDynamicEditorGridLayout()
         {
             InitializeComponent();
@@ -40,17 +48,23 @@ namespace InABox.DynamicGrid
                 var tab = new DynamicTabItem();
                 tab.Header = page.Caption();
                 if (page is FrameworkElement element)
-                    element.Margin  = new Thickness(0, 2, 0, 0);
+                    element.Margin = new Thickness(0, 2, 0, 0);
                 tab.Content = page;
 
+                var minSize = page.MinimumSize();
+
                 if(page is DynamicEditorGrid.DynamicEditPage)
                 {
                     Editors.Items.Add(tab);
+                    _editorHeight = Math.Max(_editorHeight, minSize.Height);
+                    _totalWidth = Math.Max(_totalWidth, minSize.Width);
                 }
                 else
                 {
                     OtherPages.Items.Add(tab);
+                    _pageHeight = Math.Max(_pageHeight, minSize.Height);
                 }
+
             }
 
             Editors.SelectedIndex = 0;