|
@@ -32,192 +32,6 @@ using VirtualizingCellsControl = Syncfusion.UI.Xaml.Grid.VirtualizingCellsContro
|
|
|
|
|
|
namespace InABox.DynamicGrid;
|
|
|
|
|
|
-public class DynamicGridRowStyle : DynamicGridStyle<VirtualizingCellsControl>
|
|
|
-{
|
|
|
- public DynamicGridRowStyle() : base(null)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public DynamicGridRowStyle(IDynamicGridStyle source) : base(source)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public override DependencyProperty FontSizeProperty => Control.FontSizeProperty;
|
|
|
-
|
|
|
- public override DependencyProperty FontStyleProperty => Control.FontStyleProperty;
|
|
|
-
|
|
|
- public override DependencyProperty FontWeightProperty => Control.FontWeightProperty;
|
|
|
-
|
|
|
- public override DependencyProperty BackgroundProperty => Control.BackgroundProperty;
|
|
|
-
|
|
|
- public override DependencyProperty ForegroundProperty => Control.ForegroundProperty;
|
|
|
-}
|
|
|
-
|
|
|
-public class DynamicGridCellStyle : DynamicGridStyle<Control>
|
|
|
-{
|
|
|
- public DynamicGridCellStyle() : base(null)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public DynamicGridCellStyle(IDynamicGridStyle source) : base(source)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public override DependencyProperty FontSizeProperty => Control.FontSizeProperty;
|
|
|
-
|
|
|
- public override DependencyProperty FontStyleProperty => Control.FontStyleProperty;
|
|
|
-
|
|
|
- public override DependencyProperty FontWeightProperty => Control.FontWeightProperty;
|
|
|
-
|
|
|
- public override DependencyProperty BackgroundProperty => Control.BackgroundProperty;
|
|
|
-
|
|
|
- public override DependencyProperty ForegroundProperty => Control.ForegroundProperty;
|
|
|
-}
|
|
|
-
|
|
|
-public class GridSelectionControllerExt : GridSelectionController
|
|
|
-{
|
|
|
- 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)
|
|
|
- {
|
|
|
- return null;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-public class StringArrayConverter : IValueConverter
|
|
|
-{
|
|
|
- object? IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
- {
|
|
|
- if (value is string[] strArray)
|
|
|
- {
|
|
|
- return string.Join("\n", strArray);
|
|
|
- }
|
|
|
- Logger.Send(LogType.Error, "", $"Attempt to convert an object which is not a string array: {value}.");
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
- {
|
|
|
- return value;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-[Serializable]
|
|
|
-class DynamicGridDragFormat
|
|
|
-{
|
|
|
- private string entity;
|
|
|
-
|
|
|
- public DataTable Table { get; set; }
|
|
|
-
|
|
|
- public Type Entity { get => CoreUtils.GetEntity(entity); set => entity = value.EntityName(); }
|
|
|
-
|
|
|
- public DynamicGridDragFormat(DataTable table, Type entity)
|
|
|
- {
|
|
|
- Table = table;
|
|
|
- Entity = entity;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
public abstract class DynamicGrid : ContentControl
|
|
|
{
|
|
|
public static readonly DependencyProperty UseWaitCursorProperty =
|
|
@@ -1372,6 +1186,11 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
UIComponent.AddVisualFilter(column, value, filtertype);
|
|
|
}
|
|
|
|
|
|
+ protected List<Tuple<string, Func<CoreRow, bool>>> GetFilterPredicates()
|
|
|
+ {
|
|
|
+ return UIComponent.GetFilterPredicates();
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region Item Manipulation
|
|
@@ -2393,4 +2212,195 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
+}
|
|
|
+
|
|
|
+#region Styling
|
|
|
+
|
|
|
+public class DynamicGridRowStyle : DynamicGridStyle<VirtualizingCellsControl>
|
|
|
+{
|
|
|
+ public DynamicGridRowStyle() : base(null)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public DynamicGridRowStyle(IDynamicGridStyle source) : base(source)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public override DependencyProperty FontSizeProperty => Control.FontSizeProperty;
|
|
|
+
|
|
|
+ public override DependencyProperty FontStyleProperty => Control.FontStyleProperty;
|
|
|
+
|
|
|
+ public override DependencyProperty FontWeightProperty => Control.FontWeightProperty;
|
|
|
+
|
|
|
+ public override DependencyProperty BackgroundProperty => Control.BackgroundProperty;
|
|
|
+
|
|
|
+ public override DependencyProperty ForegroundProperty => Control.ForegroundProperty;
|
|
|
+}
|
|
|
+
|
|
|
+public class DynamicGridCellStyle : DynamicGridStyle<Control>
|
|
|
+{
|
|
|
+ public DynamicGridCellStyle() : base(null)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public DynamicGridCellStyle(IDynamicGridStyle source) : base(source)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public override DependencyProperty FontSizeProperty => Control.FontSizeProperty;
|
|
|
+
|
|
|
+ public override DependencyProperty FontStyleProperty => Control.FontStyleProperty;
|
|
|
+
|
|
|
+ public override DependencyProperty FontWeightProperty => Control.FontWeightProperty;
|
|
|
+
|
|
|
+ public override DependencyProperty BackgroundProperty => Control.BackgroundProperty;
|
|
|
+
|
|
|
+ public override DependencyProperty ForegroundProperty => Control.ForegroundProperty;
|
|
|
+}
|
|
|
+
|
|
|
+public class GridSelectionControllerExt : GridSelectionController
|
|
|
+{
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+public class StringArrayConverter : IValueConverter
|
|
|
+{
|
|
|
+ object? IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
+ {
|
|
|
+ if (value is string[] strArray)
|
|
|
+ {
|
|
|
+ return string.Join("\n", strArray);
|
|
|
+ }
|
|
|
+ Logger.Send(LogType.Error, "", $"Attempt to convert an object which is not a string array: {value}.");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
|
+ {
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#endregion
|
|
|
+
|
|
|
+
|
|
|
+[Serializable]
|
|
|
+class DynamicGridDragFormat
|
|
|
+{
|
|
|
+ private string entity;
|
|
|
+
|
|
|
+ public DataTable Table { get; set; }
|
|
|
+
|
|
|
+ public Type Entity { get => CoreUtils.GetEntity(entity); set => entity = value.EntityName(); }
|
|
|
+
|
|
|
+ public DynamicGridDragFormat(DataTable table, Type entity)
|
|
|
+ {
|
|
|
+ Table = table;
|
|
|
+ Entity = entity;
|
|
|
+ }
|
|
|
}
|