Selaa lähdekoodia

Fixing some bugged code.

Kenric Nugteren 8 kuukautta sitten
vanhempi
commit
e5ab8764c0

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

@@ -1071,7 +1071,9 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
         bRefreshing = true;
         bRefreshing = true;
 
 
         if (reloadcolumns)
         if (reloadcolumns)
+        {
             ReloadColumns();
             ReloadColumns();
+        }
 
 
         if (reloaddata)
         if (reloaddata)
         {
         {

+ 9 - 9
inabox.wpf/DynamicGrid/UIComponent/DynamicGridGridUIComponent.cs

@@ -969,6 +969,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
                     newcol.ImageWidth = DataGrid.RowHeight - 8;
                     newcol.ImageWidth = DataGrid.RowHeight - 8;
                     newcol.ColumnSizer = GridLengthUnitType.None;
                     newcol.ColumnSizer = GridLengthUnitType.None;
                     newcol.HeaderText = column.HeaderText;
                     newcol.HeaderText = column.HeaderText;
+                    newcol.AllowEditing = false;
 
 
                     ApplyFilterStyle(newcol, true, true);
                     ApplyFilterStyle(newcol, true, true);
 
 
@@ -1311,13 +1312,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
 
 
     public void RefreshColumns(DynamicGridColumns columns, DynamicActionColumns actionColumns, DynamicGridColumnGroupings groupings)
     public void RefreshColumns(DynamicGridColumns columns, DynamicActionColumns actionColumns, DynamicGridColumnGroupings groupings)
     {
     {
-        // Yo, please don't remove this.
-        // The issue was when we were dynamically adding ActionColumns, and if we had to remove and then re-add them, we were getting massive performance hits
-        // for no reason. I think perhaps the image columns were trying to refer to data that didn't exist anymore when calling DataGrid.Columns.Refresh(),
-        // and thus some mega problems (perhaps even exceptions within Syncfusion) were occurring, and this seems to fix it.
-        // I don't pretend to know why it works; this is probably the strangest problem I've ever come across.
-        //DataGrid.ItemsSource = null;
-
+        DataGrid.ItemsSource = null;
         DataGrid.Columns.Suspend();
         DataGrid.Columns.Suspend();
 
 
         ColumnList.Clear();
         ColumnList.Clear();
@@ -1354,6 +1349,11 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
             }
             }
 
 
         ResizeColumns(DataGrid, DataGrid.ActualWidth - 2, DataGrid.ActualHeight - 2);
         ResizeColumns(DataGrid, DataGrid.ActualWidth - 2, DataGrid.ActualHeight - 2);
+
+        if(groupings.Count > 0)
+        {
+            RefreshData(new CoreTable());
+        }
     }
     }
 
 
     #endregion
     #endregion
@@ -1387,7 +1387,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         for (var i = 0; i < ActionColumns.Count; i++)
         for (var i = 0; i < ActionColumns.Count; i++)
             result.Columns.Add(string.Format("ActionColumn{0}", i),
             result.Columns.Add(string.Format("ActionColumn{0}", i),
                 ActionColumns[i] is DynamicImageColumn
                 ActionColumns[i] is DynamicImageColumn
-                    ? typeof(BitmapImage)
+                    ? typeof(ImageSource)
                     : typeof(String)
                     : typeof(String)
             );
             );
 
 
@@ -1403,8 +1403,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         //int rowIndex = DataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex;
         //int rowIndex = DataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex;
         //int columnIndex = DataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.ColumnIndex;
         //int columnIndex = DataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.ColumnIndex;
         //int scrollRowIndex = DataGrid.GetVisualContainer().ScrollRows.LastBodyVisibleLineIndex;
         //int scrollRowIndex = DataGrid.GetVisualContainer().ScrollRows.LastBodyVisibleLineIndex;
-        DataGrid.ItemsSource = result;
         //this.DataGrid.ScrollInView(new Syncfusion.UI.Xaml.ScrollAxis.RowColumnIndex(scrollRowIndex, columnIndex));
         //this.DataGrid.ScrollInView(new Syncfusion.UI.Xaml.ScrollAxis.RowColumnIndex(scrollRowIndex, columnIndex));
+        DataGrid.ItemsSource = result;
         ResizeColumns(DataGrid, DataGrid.ActualWidth - 1, DataGrid.ActualHeight);
         ResizeColumns(DataGrid, DataGrid.ActualWidth - 1, DataGrid.ActualHeight);
 
 
         UpdateRecordCount();
         UpdateRecordCount();

+ 73 - 64
inabox.wpf/DynamicGrid/UIComponent/DynamicGridTreeUIComponent.cs

@@ -271,86 +271,90 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
 
 
     private void _tree_Loaded(object sender, RoutedEventArgs e)
     private void _tree_Loaded(object sender, RoutedEventArgs e)
     {
     {
-        _summaryRow = new Grid();
-        _summaryRow.Visibility = Visibility.Collapsed;
-
-        var scroll = _tree.FindChild<ScrollViewer>("PART_ScrollViewer");
-        if(scroll is not null)
+        Application.Current.Dispatcher.BeginInvoke(() =>
         {
         {
-            var grid = scroll.FindVisualChildren<Grid>(recursive: false).FirstOrDefault();
-            if(grid is not null)
-            {
-                var row1 = grid.RowDefinitions[0];
-                var row2 = grid.RowDefinitions[1];
-                grid.RowDefinitions.Clear();
-                grid.RowDefinitions.Add(row1);
-                var rowDef = grid.AddRow(GridUnitType.Auto);
 
 
-                grid.RowDefinitions.Add(row2);
+            _summaryRow = new Grid();
+            _summaryRow.Visibility = Nodes is not null && Summaries.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
 
 
-                foreach(var child in grid.Children.OfType<UIElement>())
+            var scroll = _tree.FindChild<ScrollViewer>("PART_ScrollViewer");
+            if(scroll is not null)
+            {
+                var grid = scroll.FindVisualChildren<Grid>(recursive: false).FirstOrDefault();
+                if(grid is not null)
                 {
                 {
-                    var row = Grid.GetRow(child);
-                    if(row >= 1)
-                    {
-                        Grid.SetRow(child, row + 1);
-                    }
-                    else
+                    var row1 = grid.RowDefinitions[0];
+                    var row2 = grid.RowDefinitions[1];
+                    grid.RowDefinitions.Clear();
+                    grid.RowDefinitions.Add(row1);
+                    var rowDef = grid.AddRow(GridUnitType.Auto);
+
+                    grid.RowDefinitions.Add(row2);
+
+                    foreach(var child in grid.Children.OfType<UIElement>())
                     {
                     {
-                        var rowSpan = Grid.GetRowSpan(child);
-                        if(row + rowSpan >= 1 && child is ScrollBar)
+                        var row = Grid.GetRow(child);
+                        if(row >= 1)
+                        {
+                            Grid.SetRow(child, row + 1);
+                        }
+                        else
                         {
                         {
-                            Grid.SetRowSpan(child, rowSpan + 1);
+                            var rowSpan = Grid.GetRowSpan(child);
+                            if(row + rowSpan >= 1 && child is ScrollBar)
+                            {
+                                Grid.SetRowSpan(child, rowSpan + 1);
+                            }
                         }
                         }
                     }
                     }
-                }
-                var horizontalScrollbar = grid.Children.OfType<ScrollBar>().First(x => x.Orientation == Orientation.Horizontal);
+                    var horizontalScrollbar = grid.Children.OfType<ScrollBar>().First(x => x.Orientation == Orientation.Horizontal);
 
 
-                var treeGridPanel = scroll.FindChild<TreeGridPanel>("PART_TreeGridPanel");
+                    var treeGridPanel = scroll.FindChild<TreeGridPanel>("PART_TreeGridPanel");
 
 
-                var summaryScroll = new ScrollViewer
-                {
-                    VerticalScrollBarVisibility = ScrollBarVisibility.Hidden,
-                    HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden
-                };
-                summaryScroll.Content = _summaryRow;
+                    var summaryScroll = new ScrollViewer
+                    {
+                        VerticalScrollBarVisibility = ScrollBarVisibility.Hidden,
+                        HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden
+                    };
+                    summaryScroll.Content = _summaryRow;
 
 
-                scroll.ScrollChanged += (o, e) =>
-                {
-                    summaryScroll.ScrollToHorizontalOffset(scroll.HorizontalOffset);
+                    scroll.ScrollChanged += (o, e) =>
+                    {
+                        summaryScroll.ScrollToHorizontalOffset(scroll.HorizontalOffset);
 
 
-                    var panel = treeGridPanel;
-                };
+                        var panel = treeGridPanel;
+                    };
 
 
-                var transform = new TranslateTransform();
-                summaryScroll.RenderTransform = transform;
+                    var transform = new TranslateTransform();
+                    summaryScroll.RenderTransform = transform;
 
 
-                void UpdateSize(double height)
-                {
-                    var desiredHeight = treeGridPanel.RowHeights.TotalExtent;
-                    if(desiredHeight < height)
+                    void UpdateSize(double height)
                     {
                     {
-                        var diff = height - desiredHeight;
-                        transform.Y = -diff - 1;
-                    }
-                    else
-                    {
-                        transform.Y = 0;
+                        var desiredHeight = treeGridPanel.RowHeights.TotalExtent;
+                        if(desiredHeight < height)
+                        {
+                            var diff = height - desiredHeight;
+                            transform.Y = -diff - 1;
+                        }
+                        else
+                        {
+                            transform.Y = 0;
+                        }
                     }
                     }
-                }
 
 
-                treeGridPanel.SizeChanged += (o, e) =>
-                {
-                    UpdateSize(e.NewSize.Height);
-                };
-                _tree.FilterChanged += (o, e) =>
-                {
-                    UpdateSize(treeGridPanel.ActualHeight);
-                };
+                    treeGridPanel.SizeChanged += (o, e) =>
+                    {
+                        UpdateSize(e.NewSize.Height);
+                    };
+                    _tree.FilterChanged += (o, e) =>
+                    {
+                        UpdateSize(treeGridPanel.ActualHeight);
+                    };
 
 
-                grid.AddChild(summaryScroll, 1, 0);
+                    grid.AddChild(summaryScroll, 1, 0);
+                }
             }
             }
-        }
+        });
     }
     }
 
 
     private class TreeGridSelectionControllerExt(SfTreeGrid treeGrid, DynamicGridTreeUIComponent<T> grid) : TreeGridRowSelectionController(treeGrid)
     private class TreeGridSelectionControllerExt(SfTreeGrid treeGrid, DynamicGridTreeUIComponent<T> grid) : TreeGridRowSelectionController(treeGrid)
@@ -716,7 +720,7 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
                     var image = imgCol.Image?.Invoke(null);
                     var image = imgCol.Image?.Invoke(null);
                     if (image != null)
                     if (image != null)
                     {
                     {
-                        var template = new ControlTemplate(typeof(GridHeaderCellControl));
+                        var template = new ControlTemplate(typeof(TreeGridHeaderCell));
                         var border = new FrameworkElementFactory(typeof(Border));
                         var border = new FrameworkElementFactory(typeof(Border));
                         border.SetValue(Border.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro));
                         border.SetValue(Border.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro));
                         border.SetValue(Border.PaddingProperty, new Thickness(4));
                         border.SetValue(Border.PaddingProperty, new Thickness(4));
@@ -1014,7 +1018,7 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
 
 
                     var headstyle = GetHeaderCellStyle(column);
                     var headstyle = GetHeaderCellStyle(column);
                     headstyle.Setters.Add(new EventSetter(Control.MouseLeftButtonUpEvent, new MouseButtonEventHandler(HeaderCell_LeftMouseButtonEvent)));
                     headstyle.Setters.Add(new EventSetter(Control.MouseLeftButtonUpEvent, new MouseButtonEventHandler(HeaderCell_LeftMouseButtonEvent)));
-                    newcol.HeaderStyle = GetHeaderCellStyle(column);
+                    newcol.HeaderStyle = headstyle;
 
 
                     _tree.Columns.Add(newcol);
                     _tree.Columns.Add(newcol);
                     ColumnList.Add(column);
                     ColumnList.Add(column);
@@ -1306,6 +1310,8 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
 
 
     private void RebuildSummaryRow()
     private void RebuildSummaryRow()
     {
     {
+        if (_summaryRow is null) return;
+
         _summaryRow.RowDefinitions.Clear();
         _summaryRow.RowDefinitions.Clear();
         _summaryRow.ColumnDefinitions.Clear();
         _summaryRow.ColumnDefinitions.Clear();
         _summaryRow.Children.Clear();
         _summaryRow.Children.Clear();
@@ -1465,7 +1471,10 @@ public class DynamicGridTreeUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
         nodes.ColumnChanged += Nodes_ColumnChanged;
         nodes.ColumnChanged += Nodes_ColumnChanged;
         Nodes = nodes;
         Nodes = nodes;
         _tree.ItemsSource = nodes.Nodes;
         _tree.ItemsSource = nodes.Nodes;
-        _summaryRow.Visibility = Visibility.Visible;
+        if(_summaryRow is not null && Summaries.Count > 0)
+        {
+            _summaryRow.Visibility = Visibility.Visible;
+        }
 
 
         CalculateSummaries();
         CalculateSummaries();