123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using System;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using InABox.Core;
- using Image = System.Windows.Controls.Image;
- using Label = System.Windows.Controls.Label;
- namespace InABox.DynamicGrid
- {
- public abstract class DynamicActionColumn : DynamicColumnBase
- {
- public DynamicActionColumnPosition Position { get; set; }
-
- public Func<CoreRow?, bool>? Action { get; set; }
- public Func<DynamicActionColumn, CoreRow?, FrameworkElement?>? ToolTip { get; set; }
-
- public string[] SelectedFilters { get; set; }
- public string[] Filters { get; set; }
- public Func<CoreRow, string[], bool> FilterRecord { get; set; }
- public Func<CoreRow[], ContextMenu> ContextMenu { get; set; }
- public object Tag { get; set; }
- public string HeaderText { get; set; }
- public bool VerticalHeader { get; set; }
- public int Width { get; set; }
-
- protected override void Init()
- {
- base.Init();
- Width = 0;
- HeaderText = " ";
- Filters = null;
- FilterRecord = null;
- Position = DynamicActionColumnPosition.End;
- }
- public FrameworkElement? TextToolTip(string text)
- {
- if (string.IsNullOrWhiteSpace(text))
- return null;
- var border = new Border
- {
- BorderBrush = new SolidColorBrush(Colors.Gray),
- BorderThickness = new Thickness(0.75),
- CornerRadius = new CornerRadius(5),
- Background = new SolidColorBrush(Colors.LightYellow),
- Padding = new Thickness(5),
- Child = new Label { Content = text }
- };
- return border;
- }
- public FrameworkElement? ImageToolTip(BitmapImage image)
- {
- if (image == null)
- return null;
- var result = new Border
- {
- Background = new SolidColorBrush(Colors.LightYellow),
- BorderBrush = new SolidColorBrush(Colors.Gray),
- BorderThickness = new Thickness(0.75)
- };
- result.Child = new Image { Source = image };
- return result;
- }
- public abstract object Data(CoreRow? row);
- }
- public class DynamicTextColumn : DynamicActionColumn
- {
- public Func<CoreRow?, String> Text { get; private set; }
-
- public Alignment Alignment { get; set; }
-
- public DynamicTextColumn(Func<CoreRow?, String?> text, Func<CoreRow?, bool>? action = null)
- {
- Alignment = Alignment.MiddleCenter;
- Text = text;
- Action = action;
- VerticalHeader = false;
- }
- public override object Data(CoreRow? row) => Text?.Invoke(row);
- }
-
- public class DynamicImageColumn : DynamicActionColumn
- {
- public DynamicImageColumn(Func<CoreRow?, BitmapImage?> image, Func<CoreRow?, bool>? action = null)
- {
- Image = image;
- Action = action;
- VerticalHeader = true;
- }
- public DynamicImageColumn(BitmapImage image, Func<CoreRow?, bool>? action = null)
- {
- Image = r => image;
- Action = action;
- }
- public Func<CoreRow?, BitmapImage?> Image { get; protected set; }
-
- public bool AllowHeaderClick { get; set; }
- protected override void Init()
- {
- base.Init();
- AllowHeaderClick = false;
- }
-
- public override object Data(CoreRow? row) => Image?.Invoke(row);
- }
-
- }
|