|
@@ -8,7 +8,6 @@ using Syncfusion.UI.Xaml.Grid;
|
|
|
using Syncfusion.UI.Xaml.Grid.Cells;
|
|
|
using Syncfusion.UI.Xaml.Grid.Helpers;
|
|
|
using Syncfusion.UI.Xaml.ScrollAxis;
|
|
|
-using Syncfusion.Windows.Shared;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
@@ -26,9 +25,18 @@ using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Threading;
|
|
|
using DataRow = System.Data.DataRow;
|
|
|
+using TimeSpanEdit = Syncfusion.Windows.Shared.TimeSpanEdit;
|
|
|
|
|
|
namespace InABox.DynamicGrid;
|
|
|
|
|
|
+public enum DynamicGridLines
|
|
|
+{
|
|
|
+ Both,
|
|
|
+ Horizontal,
|
|
|
+ Vertical,
|
|
|
+ None
|
|
|
+}
|
|
|
+
|
|
|
public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynamicGridGridUIComponent<T>
|
|
|
where T : BaseObject, new()
|
|
|
{
|
|
@@ -52,7 +60,8 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
CellFontWeightConverter = new DynamicGridCellStyleConverter<System.Windows.FontWeight?>(Parent, GetCellFontWeight);
|
|
|
|
|
|
DataGrid.RowStyleSelector = Parent.RowStyleSelector;
|
|
|
- DataGrid.TableSummaryCellStyleSelector = new DynamicGridSummaryStyleSelector(Parent);
|
|
|
+ DataGrid.TableSummaryRowStyleSelector = new SummaryRowStyleSelector(this, GetSummaryRowStyle);
|
|
|
+ DataGrid.TableSummaryCellStyleSelector = new SummaryCellStyleSelector(this, GetSummaryCellStyle);
|
|
|
}
|
|
|
}
|
|
|
FrameworkElement IDynamicGridUIComponent<T>.Control => DataGrid;
|
|
@@ -82,6 +91,39 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
private DynamicGridCellStyleConverter<System.Windows.FontStyle?> CellFontStyleConverter;
|
|
|
private DynamicGridCellStyleConverter<System.Windows.FontWeight?> CellFontWeightConverter;
|
|
|
|
|
|
+ #region Configuration
|
|
|
+
|
|
|
+ private DynamicGridLines _gridLines = DynamicGridLines.Both;
|
|
|
+ public DynamicGridLines GridLines
|
|
|
+ {
|
|
|
+ get => _gridLines;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ _gridLines = value;
|
|
|
+ DataGrid.GridLinesVisibility = value switch
|
|
|
+ {
|
|
|
+ DynamicGridLines.Both => GridLinesVisibility.Both,
|
|
|
+ DynamicGridLines.Vertical => GridLinesVisibility.Vertical,
|
|
|
+ DynamicGridLines.Horizontal => GridLinesVisibility.Horizontal,
|
|
|
+ _ => GridLinesVisibility.None,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public double RowHeight
|
|
|
+ {
|
|
|
+ get => DataGrid.RowHeight;
|
|
|
+ set => DataGrid.RowHeight = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double HeaderRowHeight
|
|
|
+ {
|
|
|
+ get => DataGrid.HeaderRowHeight;
|
|
|
+ set => DataGrid.HeaderRowHeight = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
public DynamicGridGridUIComponent()
|
|
|
{
|
|
|
ColumnsMenu = new ContextMenu();
|
|
@@ -159,12 +201,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
//DataGrid.MouseMove += DataGrid_MouseMove;
|
|
|
DataGrid.CellToolTipOpening += DataGrid_CellToolTipOpening;
|
|
|
|
|
|
- //var headstyle = new Style(typeof(GridHeaderCellControl));
|
|
|
- //headstyle.Setters.Add(new Setter(GridHeaderCellControl.BackgroundProperty, new SolidColorBrush(Colors.WhiteSmoke)));
|
|
|
- //headstyle.Setters.Add(new Setter(GridHeaderCellControl.ForegroundProperty, new SolidColorBrush(Colors.Green)));
|
|
|
- //headstyle.Setters.Add(new Setter(GridHeaderCellControl.FontSizeProperty, 12.0F));
|
|
|
- //DataGrid.HeaderStyle = headstyle;
|
|
|
-
|
|
|
DataGrid.SizeChanged += DataGrid_SizeChanged;
|
|
|
|
|
|
//DataGrid.CellRenderers.Remove("Numeric");
|
|
@@ -456,18 +492,6 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
StopTimer();
|
|
|
Parent.DoubleClickCell(GetRowFromIndex(e.RowColumnIndex.RowIndex), GetColumn(e.RowColumnIndex.ColumnIndex));
|
|
|
}
|
|
|
-
|
|
|
- public double RowHeight
|
|
|
- {
|
|
|
- get => DataGrid.RowHeight;
|
|
|
- set => DataGrid.RowHeight = value;
|
|
|
- }
|
|
|
-
|
|
|
- public double HeaderRowHeight
|
|
|
- {
|
|
|
- get => DataGrid.HeaderRowHeight;
|
|
|
- set => DataGrid.HeaderRowHeight = value;
|
|
|
- }
|
|
|
|
|
|
private void DataGrid_QueryRowHeight(object? sender, QueryRowHeightEventArgs e)
|
|
|
{
|
|
@@ -666,6 +690,78 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
protected virtual FontStyle? GetCellFontStyle(CoreRow row, DynamicColumnBase column) => null;
|
|
|
protected virtual FontWeight? GetCellFontWeight(CoreRow row, DynamicColumnBase column) => null;
|
|
|
|
|
|
+ protected virtual Style GetHeaderCellStyle(DynamicColumnBase column)
|
|
|
+ {
|
|
|
+ var headStyle = new Style(typeof(GridHeaderCellControl));
|
|
|
+
|
|
|
+ headStyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
|
|
|
+ headStyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
|
|
|
+ headStyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
|
|
|
+
|
|
|
+ if(column is DynamicActionColumn actionColumn)
|
|
|
+ {
|
|
|
+ headStyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.0)));
|
|
|
+ headStyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 1, 1)));
|
|
|
+ if(column is DynamicImageColumn imgCol)
|
|
|
+ {
|
|
|
+ if (imgCol.HeaderText.IsNullOrWhiteSpace())
|
|
|
+ {
|
|
|
+ var image = imgCol.Image?.Invoke(null);
|
|
|
+ if (image != null)
|
|
|
+ {
|
|
|
+ var template = new ControlTemplate(typeof(GridHeaderCellControl));
|
|
|
+ var border = new FrameworkElementFactory(typeof(Border));
|
|
|
+ border.SetValue(Border.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro));
|
|
|
+ border.SetValue(Border.PaddingProperty, new Thickness(4));
|
|
|
+ var img = new FrameworkElementFactory(typeof(Image));
|
|
|
+ img.SetValue(Image.SourceProperty, image);
|
|
|
+ border.AppendChild(img);
|
|
|
+ template.VisualTree = border;
|
|
|
+ headStyle.Setters.Add(new Setter(Control.TemplateProperty, template));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (actionColumn.VerticalHeader && !actionColumn.HeaderText.IsNullOrWhiteSpace())
|
|
|
+ {
|
|
|
+ headStyle.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty, HorizontalAlignment.Left));
|
|
|
+ headStyle.Setters.Add(new Setter(Control.TemplateProperty,
|
|
|
+ Application.Current.Resources["VerticalColumnHeader"] as ControlTemplate));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return headStyle;
|
|
|
+ }
|
|
|
+ protected virtual Style GetSummaryRowStyle()
|
|
|
+ {
|
|
|
+ var style = new Style(typeof(TableSummaryRowControl));
|
|
|
+
|
|
|
+ return style;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected virtual Style GetSummaryCellStyle(DynamicColumnBase column)
|
|
|
+ {
|
|
|
+ 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)));
|
|
|
+
|
|
|
+ if(column is DynamicGridColumn gridColumn)
|
|
|
+ {
|
|
|
+ style.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty,
|
|
|
+ column != null ? gridColumn.HorizontalAlignment(typeof(double)) : HorizontalAlignment.Right));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ style.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty, 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;
|
|
|
+ }
|
|
|
+
|
|
|
#region Columns
|
|
|
|
|
|
private class StackedHeaderRenderer : GridStackedHeaderCellRenderer
|
|
@@ -800,38 +896,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
style.Setters.Add(new Setter(Control.IsEnabledProperty, false));
|
|
|
newcol.FilterRowCellStyle = style;
|
|
|
|
|
|
- var headstyle = new Style(typeof(GridHeaderCellControl));
|
|
|
- headstyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
|
|
|
- if (!string.IsNullOrWhiteSpace(column.HeaderText))
|
|
|
- {
|
|
|
- //headstyle.Setters.Add(new Setter(LayoutTransformProperty, new RotateTransform(270.0F)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.0, 0.0, 0, 0)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 1, 1)));
|
|
|
- if (imgcol.VerticalHeader)
|
|
|
- headstyle.Setters.Add(new Setter(Control.TemplateProperty,
|
|
|
- Application.Current.Resources["VerticalColumnHeader"] as ControlTemplate));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var image = imgcol.Image?.Invoke(null);
|
|
|
- if (image != null)
|
|
|
- {
|
|
|
- var template = new ControlTemplate(typeof(GridHeaderCellControl));
|
|
|
- var border = new FrameworkElementFactory(typeof(Border));
|
|
|
- border.SetValue(Border.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro));
|
|
|
- border.SetValue(Border.PaddingProperty, new Thickness(4));
|
|
|
- border.SetValue(Control.MarginProperty, new Thickness(0, 0, 1, 1));
|
|
|
- var img = new FrameworkElementFactory(typeof(Image));
|
|
|
- img.SetValue(Image.SourceProperty, image);
|
|
|
- border.AppendChild(img);
|
|
|
- template.VisualTree = border;
|
|
|
- headstyle.Setters.Add(new Setter(Control.TemplateProperty, template));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- newcol.HeaderStyle = headstyle;
|
|
|
+ newcol.HeaderStyle = GetHeaderCellStyle(column);
|
|
|
|
|
|
DataGrid.Columns.Add(newcol);
|
|
|
ColumnList.Add(column);
|
|
@@ -869,20 +934,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
style.Setters.Add(new Setter(Control.IsEnabledProperty, false));
|
|
|
newcol.FilterRowCellStyle = style;
|
|
|
|
|
|
- var headstyle = new Style(typeof(GridHeaderCellControl));
|
|
|
- headstyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
|
|
|
- headstyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.0, 0.0, 0, 0)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 1, 1)));
|
|
|
- if (txtCol.VerticalHeader)
|
|
|
- {
|
|
|
- headstyle.Setters.Add(new Setter(Control.HorizontalContentAlignmentProperty, HorizontalAlignment.Left));
|
|
|
- headstyle.Setters.Add(new Setter(Control.TemplateProperty,
|
|
|
- Application.Current.Resources["VerticalColumnHeader"] as ControlTemplate));
|
|
|
- }
|
|
|
-
|
|
|
- newcol.HeaderStyle = headstyle;
|
|
|
+ newcol.HeaderStyle = GetHeaderCellStyle(column);
|
|
|
|
|
|
var cellstyle = new Style();
|
|
|
cellstyle.Setters.Add(new Setter(Control.BackgroundProperty,
|
|
@@ -944,13 +996,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
style.Setters.Add(new Setter(Control.IsEnabledProperty, false));
|
|
|
newcol.FilterRowCellStyle = style;
|
|
|
|
|
|
- var headstyle = new Style(typeof(GridHeaderCellControl));
|
|
|
- headstyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
|
|
|
- headstyle.Setters.Add(new Setter(Control.MarginProperty, new Thickness(0, 0, 1, 1)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.BorderThicknessProperty, new Thickness(0.0)));
|
|
|
- newcol.HeaderStyle = headstyle;
|
|
|
+ newcol.HeaderStyle = GetHeaderCellStyle(column);
|
|
|
|
|
|
var cellstyle = new Style();
|
|
|
cellstyle.Setters.Add(new Setter(Control.BackgroundProperty,
|
|
@@ -992,6 +1038,33 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ public class SummaryRowStyleSelector(DynamicGridGridUIComponent<T> parent, Func<Style> selector) : StyleSelector
|
|
|
+ {
|
|
|
+ public DynamicGridGridUIComponent<T> Parent { get; init; } = parent;
|
|
|
+
|
|
|
+ public Func<Style> Selector { get; set; } = selector;
|
|
|
+
|
|
|
+ public override Style? SelectStyle(object item, DependencyObject container)
|
|
|
+ {
|
|
|
+ return Selector();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public class SummaryCellStyleSelector(DynamicGridGridUIComponent<T> parent, Func<DynamicColumnBase, Style> selector) : StyleSelector
|
|
|
+ {
|
|
|
+ public DynamicGridGridUIComponent<T> Parent { get; init; } = parent;
|
|
|
+
|
|
|
+ public Func<DynamicColumnBase, Style> Selector { get; set; } = selector;
|
|
|
+
|
|
|
+ public override Style? SelectStyle(object item, DependencyObject container)
|
|
|
+ {
|
|
|
+ var vcol = ((GridTableSummaryCell)container).ColumnBase.ColumnIndex;
|
|
|
+
|
|
|
+ var col = Parent.GetColumn(vcol);
|
|
|
+
|
|
|
+ return col is not null ? Selector(col) : null;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public class TemplateColumnSelector(DynamicGridGridUIComponent<T> parent, Func<CoreRow, FrameworkElement?> dataTemplate) : DataTemplateSelector
|
|
|
{
|
|
@@ -1081,11 +1154,7 @@ public class DynamicGridGridUIComponent<T> : IDynamicGridUIComponent<T>, IDynami
|
|
|
|
|
|
ApplyFilterStyle(newColumn, newcol.Filtered, false);
|
|
|
|
|
|
- var headstyle = new Style(typeof(GridHeaderCellControl));
|
|
|
- headstyle.Setters.Add(new Setter(Control.BackgroundProperty, new SolidColorBrush(Colors.Gainsboro)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.ForegroundProperty, new SolidColorBrush(Colors.Black)));
|
|
|
- headstyle.Setters.Add(new Setter(Control.FontSizeProperty, 12D));
|
|
|
- newColumn.HeaderStyle = headstyle;
|
|
|
+ newColumn.HeaderStyle = GetHeaderCellStyle(column);
|
|
|
|
|
|
var cellstyle = new Style();
|
|
|
if (Parent.IsDirectEditMode())
|