Forráskód Böngészése

Adding new customisation options to tree view

Kenric Nugteren 1 éve
szülő
commit
b22045519e

+ 8 - 17
InABox.Core/CoreTreeNodes.cs

@@ -35,17 +35,6 @@ namespace InABox.Core
                 RaisedOnPropertyChanged("Parent");
             }
         }
-
-        private string _description;
-        public string Description
-        {
-            get { return _description; }
-            set
-            {
-                _description = value;
-                RaisedOnPropertyChanged("Description");
-            }
-        }
    
         private object _image;
         public object Image
@@ -84,7 +73,6 @@ namespace InABox.Core
         public CoreTreeNode(CoreTreeNodes owner, CoreRow row)
         {
             _owner = owner;
-            _description = "";
             _row = row;
         }
 
@@ -156,13 +144,17 @@ namespace InABox.Core
         public CoreTreeNode? Find(CoreRow row) => _nodes.FirstOrDefault(x => x.Row == row);
 
         /// <summary>
-        /// Get all the children, recursively, of a given node, given by <paramref name="id"/>.
+        /// Gets a given node and recursively all its children given by <paramref name="id"/>.
         /// </summary>
         /// <param name="id"></param>
         /// <returns></returns>
         public IEnumerable<CoreTreeNode> GetChildren(Guid id)
         {
-            yield return _nodeMap[id];
+            if(!_nodeMap.TryGetValue(id, out var node))
+            {
+                yield break;
+            }
+            yield return node;
             var children = GetChildrenOfParent(id);
             foreach (var child in children)
                 foreach (var item in GetChildren(child.ID))
@@ -179,15 +171,14 @@ namespace InABox.Core
             return _nodes.Where(x => x.Parent.Equals(id) && (x.ID != id));
         }
 
-        public void Load<T>(CoreTable table, Expression<Func<T, Guid>> id, Expression<Func<T, Guid>> parentid, Expression<Func<T, String>> description)
+        public void Load<T>(CoreTable table, Expression<Func<T, Guid>> id, Expression<Func<T, Guid>> parentid)
         {
             _nodes.Clear();
             foreach (var row in table.Rows)
             {
                 var _id = row.Get(id);
                 var _parent = row.Get(parentid);
-                var _description = row.Get(description);
-                Add(_id, _parent, row).Description = _description;
+                Add(_id, _parent, row);
             }
         }
         

+ 0 - 107
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -180,115 +180,8 @@ public class StringToColorImageConverter : IValueConverter
 
     public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
     {
-<<<<<<< HEAD
         var str = value?.ToString();
         if (str is null)
-=======
-        public GridSelectionControllerExt(SfDataGrid datagrid)
-            : base(datagrid)
-        {
-        }
-
-        protected override void ProcessSelectedItemChanged(SelectionPropertyChangedHandlerArgs handle)
-        {
-            base.ProcessSelectedItemChanged(handle);
-            if (handle.NewValue != null)
-            {
-                //this.DataGrid.ScrollInView(this.CurrentCellManager.CurrentRowColumnIndex);
-                //int rowIndex = this.CurrentCellManager.CurrentRowColumnIndex.RowIndex;
-                var columnIndex = CurrentCellManager.CurrentRowColumnIndex.ColumnIndex;
-                var scrollRowIndex = DataGrid.GetVisualContainer().ScrollRows.LastBodyVisibleLineIndex;
-                DataGrid.ScrollInView(new RowColumnIndex(scrollRowIndex, columnIndex));
-            }
-        }
-    }
-
-    public class DynamicGridSummaryStyleSelector : StyleSelector
-    {
-        private readonly IDynamicGrid _grid;
-
-        public DynamicGridSummaryStyleSelector(IDynamicGrid grid)
-        {
-            _grid = grid;
-        }
-
-        public override Style SelectStyle(object item, DependencyObject container)
-        {
-            var vcol = ((GridTableSummaryCell)container).ColumnBase.ColumnIndex;
-            var col = vcol > -1 && vcol < _grid.VisibleColumns.Count ? _grid.VisibleColumns[vcol] : null;
-
-            var style = new Style(typeof(GridTableSummaryCell));
-            style.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
-            style.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
-            style.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty,
-                col != null ? col.HorizontalAlignment(typeof(double)) : HorizontalAlignment.Right));
-            style.Setters.Add(new Setter(Control.BorderBrushProperty, new SolidColorBrush(Colors.Gray)));
-            style.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0, 0, 0.75, 0)));
-            style.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
-            style.Setters.Add(new Setter(Control.FontWeightProperty, FontWeights.DemiBold));
-            return style;
-        }
-    }
-
-    // Used to render boolean columns (the default "false" value shows what appears to be an intermediate state, which is ugly
-    // This should show nothing for false, and a tick in a box for true
-    public class BoolToImageConverter : AbstractConverter<bool,ImageSource>
-    {
-
-        public ImageSource TrueValue { get; set; }
-        public ImageSource FalseValue { get; set; }
-
-        public BoolToImageConverter()
-        {
-            TrueValue = Wpf.Resources.Bullet_Tick.AsBitmapImage();
-        }
-        
-        public override ImageSource Convert(bool value)
-        {
-            return value ? TrueValue : FalseValue;
-        }
-
-        public override bool Deconvert(ImageSource value)
-        {
-            return ImageUtils.IsEqual(value as BitmapImage,TrueValue as BitmapImage);
-        }
-    }
-
-    public class StringToColorImageConverter : IValueConverter
-    {
-        private readonly int _height = 50;
-        private readonly int _width = 25;
-        private readonly Dictionary<string, BitmapImage> cache = new();
-
-        public StringToColorImageConverter(int width, int height)
-        {
-            _width = width;
-            _height = height;
-        }
-
-        public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
-        {
-            var str = value?.ToString();
-            if (str is null)
-                return null;
-
-            var colorcode = str.TrimStart('#');
-
-            if (!cache.ContainsKey(colorcode))
-            {
-                var col = ImageUtils.StringToColor(colorcode);
-                var bmp = ImageUtils.BitmapFromColor(col, _width, _height, Color.Black);
-                cache[colorcode] = bmp.AsBitmapImage();
-            }
-
-            var result = cache[colorcode];
-            return result;
-        }
-
-
-        public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
-        {
->>>>>>> origin/frank
             return null;
 
         var colorcode = str.TrimStart('#');

+ 28 - 8
inabox.wpf/DynamicGrid/UIComponent/DynamicGridTreeUIComponent.cs

@@ -57,13 +57,11 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
 
             Parent.AddHiddenColumn(IDColumn.Property);
             Parent.AddHiddenColumn(ParentColumn.Property);
-            Parent.AddHiddenColumn(DescriptionColumn.Property);
         }
     }
 
     private Column<T> IDColumn;
     private Column<T> ParentColumn;
-    private Column<T> DescriptionColumn;
 
     private ContextMenu _menu;
     private SfTreeGrid _tree;
@@ -84,6 +82,28 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         } 
     }
 
+    private bool _showHeader = false;
+    public bool ShowHeader
+    {
+        get => _showHeader;
+        set
+        {
+            _showHeader = value;
+            _tree.HeaderRowHeight = value ? 30 : 0;
+        }
+    }
+
+    private bool _autoSizeExpander = false;
+    public bool AutoSizeExpander
+    {
+        get => _autoSizeExpander;
+        set
+        {
+            _autoSizeExpander = value;
+            _tree.AllowAutoSizingExpanderColumn = value;
+        }
+    }
+
     private DynamicTreeGridLines _gridLines = DynamicTreeGridLines.Both;
     public DynamicTreeGridLines GridLines
     {
@@ -166,11 +186,10 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
     protected virtual FontWeight? GetCellFontWeight(CoreRow row, String columnname) => null;
 
 
-    public DynamicGridTreeUIComponent(Expression<Func<T, Guid>> idColumn, Expression<Func<T, Guid>> parentIDColumn, Expression<Func<T, string>> descriptionColumn)
+    public DynamicGridTreeUIComponent(Expression<Func<T, Guid>> idColumn, Expression<Func<T, Guid>> parentIDColumn)
     {
         IDColumn = new Column<T>(CoreUtils.GetFullPropertyName(idColumn, "."));
         ParentColumn = new Column<T>(CoreUtils.GetFullPropertyName(parentIDColumn, "."));
-        DescriptionColumn = new Column<T>(CoreUtils.GetFullPropertyName(descriptionColumn, "."));
 
         ColumnsMenu = new ContextMenu();
         ColumnsMenu.Opened += ColumnsMenu_ContextMenuOpening;
@@ -179,7 +198,7 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         _tree.ChildPropertyName = "Children";
         //_tree.ParentPropertyName = "Parent";
         _tree.AutoGenerateColumns = false;
-        ExpandMode = ExpandMode.All;
+        ExpandMode = DynamicTreeGridExpandMode.All;
         //_tree.NodeCollapsing += (o, e) => { e.Cancel = true; };
         //_tree.HeaderRowHeight = 0D;
         _tree.HeaderRowHeight = 30;
@@ -220,6 +239,8 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         _tree.RowHeight = 30D;
         _tree.SetValue(Grid.RowProperty, 0);
 
+        _tree.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Visible);
+
         _tree.AllowDraggingRows = false;
         _tree.Drop += _tree_Drop;
         _tree.DragOver += _tree_DragOver;
@@ -241,7 +262,7 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
 
     public IEnumerable<CoreRow> GetChildren(Guid id)
     {
-        return Nodes.GetChildren(id).Select(x => MapRow(x.Row));
+        return Nodes.GetChildren(id).Select(x => MapRow(x.Row)).NotNull();
     }
 
     #endregion
@@ -902,8 +923,7 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
 
             var _id = row.Get<Guid>(IDColumn.Property);
             var _parent = row.Get<Guid>(ParentColumn.Property);
-            var _description = row.Get<string>(DescriptionColumn.Property);
-            nodes.Add(_id, _parent, newRow).Description = _description;
+            nodes.Add(_id, _parent, newRow);
         }
         Nodes = nodes;
         _tree.ItemsSource = nodes.Nodes;