소스 검색

CheckListBox Editor is now multi-column

frogsoftware 1 년 전
부모
커밋
ad117e7d5b
2개의 변경된 파일56개의 추가작업 그리고 15개의 파일을 삭제
  1. 8 1
      InABox.Core/Editors/CheckListEditor.cs
  2. 48 14
      inabox.wpf/DynamicGrid/Editors/CheckListEditor/CheckListEditorControl.cs

+ 8 - 1
InABox.Core/Editors/CheckListEditor.cs

@@ -4,13 +4,20 @@ namespace InABox.Core
 {
     public class CheckListEditor : BaseComboEditor
     {
+        
+        public double ColumnWidth { get; set; }
+        
         public CheckListEditor(Type generator) : base(generator)
         {
+            ColumnWidth = 100.0;
         }
 
         protected override BaseEditor DoClone()
         {
-            return CloneBaseComboEditor();
+            var result =  CloneBaseComboEditor();
+            if (result is CheckListEditor cbe)
+                cbe.ColumnWidth = this.ColumnWidth;
+            return result;
         }
     }
 }

+ 48 - 14
inabox.wpf/DynamicGrid/Editors/CheckListEditor/CheckListEditorControl.cs

@@ -2,10 +2,16 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Markup;
 using System.Windows.Media;
 using InABox.Core;
+using InABox.WPF;
+using RoslynPad.Editor;
 using Syncfusion.Windows.Shared;
 using Syncfusion.Windows.Tools.Controls;
+using ItemsPanelTemplate = System.Windows.Controls.ItemsPanelTemplate;
 
 namespace InABox.DynamicGrid
 {
@@ -15,6 +21,7 @@ namespace InABox.DynamicGrid
         static CheckListEditorControl()
         {
             //DynamicEditorControlFactory.Register<CheckListEditorControl, CheckListEditor>();
+            
         }
         
         private SolidColorBrush _color;
@@ -34,11 +41,8 @@ namespace InABox.DynamicGrid
         public override void Configure()
         {
             if (EditorDefinition is not CheckListEditor editor) return;
-
-            Width = editor.LookupWidth;
-            Editor.IsEnabled = false;
-            Editor.Background = Brushes.WhiteSmoke;
-
+            Editor.ItemsPanel = GetItemsPanelTemplate(editor.Width);
+            Editor.ItemContainerStyle = GetItemsContainerStyle(editor.ColumnWidth);
             Host.LoadLookups(this);
         }
 
@@ -61,20 +65,50 @@ namespace InABox.DynamicGrid
             SetupCheckListBox();
         }
 
+        private class WidthConverter : AbstractConverter<double, double>
+        {
+            public CheckListEditorControl Parent { get; set; }
+            
+            public override double Convert(double value)
+            {
+                return value - 10.0;
+            }
+        }
+        
+        private ItemsPanelTemplate? GetItemsPanelTemplate(double width)
+        {
+	        FrameworkElementFactory fc = new FrameworkElementFactory(typeof(WrapPanel));
+            var binding = new Binding()
+            {
+                RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(CheckListBox), 1),
+                Path = new PropertyPath(nameof(ActualWidth)),
+                Converter = new WidthConverter() { Parent = this }
+            };
+            fc.SetBinding(WidthProperty,binding);
+            //fc.SetValue(BackgroundProperty, new SolidColorBrush(Colors.LightBlue));
+	        ItemsPanelTemplate ipt = new ItemsPanelTemplate(fc);
+	        return ipt;
+        }
+
+        private Style? GetItemsContainerStyle(double width)
+        {
+            var style = new Style(typeof(CheckListBoxItem));                
+            style.Setters.Add(new Setter {Property = WidthProperty, Value = width});
+            //style.Setters.Add(new Setter {Property = BackgroundProperty, Value = new SolidColorBrush(Colors.Red)});
+            return style;
+        }
+        
+        
         protected override FrameworkElement CreateEditor()
         {
-            MinHeight = 50;
+            
             Editor = new CheckListBox
             {
-                VerticalAlignment = VerticalAlignment.Stretch,
-                VerticalContentAlignment = VerticalAlignment.Top,
-                HorizontalAlignment = HorizontalAlignment.Stretch,
-                //SelectedItemBackground = Brushes.Transparent,
-                //Foreground = Brushes.Black
                 DisplayMemberPath = "Value",
-                SelectedValuePath = "Key"
+                SelectedValuePath = "Key",
+                HorizontalAlignment = HorizontalAlignment.Stretch
             };
-            SkinStorage.SetVisualStyle(Editor, "Metro");
+            //SkinStorage.SetVisualStyle(Editor, "Metro");
             Editor.SelectionChanged += (o, e) =>
             {
                 if (!bLoading)
@@ -85,7 +119,7 @@ namespace InABox.DynamicGrid
 
         public override int DesiredWidth()
         {
-            return 150;
+            return int.MaxValue;
         }
 
         protected override Dictionary<string, bool> RetrieveValue()