using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using InABox.Core; using InABox.WPF; using Microsoft.Xaml.Behaviors; using Syncfusion.UI.Xaml.Grid; namespace InABox.DynamicGrid; public abstract class DynamicGridMaskColumn : DynamicGridEditorColumn where TEntity : BaseObject where TEditor : class,new() { protected abstract Behavior CreateBehaviour(); protected abstract IValueConverter CreateConverter(); protected abstract Button[] CreateButtons(TextBox textbox); protected override void Configure(GridTemplateColumn column, TEditor editor) { var converter = CreateConverter(); column.CellTemplate = TemplateGenerator.CreateDataTemplate ( () => { var result = new Label(); result.HorizontalContentAlignment = Column.TextAlignment == TextAlignment.Left ? HorizontalAlignment.Left : Column.TextAlignment == TextAlignment.Center ? HorizontalAlignment.Center : HorizontalAlignment.Right; var binding = new Binding() { Path = new PropertyPath(MappingName), Converter = converter }; result.SetBinding(Label.ContentProperty, binding); return result; } ); column.EditTemplate = TemplateGenerator.CreateDataTemplate ( () => { var result = new Grid(); result.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star)}); result.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto)}); var textbox = new TextBox(); textbox.CharacterCasing = CharacterCasing.Upper; textbox.TextAlignment = Column.TextAlignment; textbox.SetBinding(TextBox.TextProperty, new Binding() { Path = new PropertyPath(MappingName), Converter = converter }); textbox.SetValue(Grid.ColumnSpanProperty, 2); textbox.Padding = new Thickness(2, 0, 0, 0); textbox.VerticalContentAlignment = VerticalAlignment.Center; textbox.SetValue(FocusManagerHelper.FocusedElementProperty, true); Interaction.GetBehaviors(textbox).Add(CreateBehaviour()); result.Children.Add(textbox); var padding = 0.0; var buttons = CreateButtons(textbox); if (buttons?.Any() == true) { StackPanel stack = new StackPanel() { Orientation = Orientation.Horizontal }; stack.SetValue(Grid.ColumnProperty,1); result.Children.Add(stack); foreach (var button in buttons) { button.Margin = new Thickness(1); button.BorderThickness = new Thickness(0.75, 0, 0, 0); stack.Children.Add(button); padding += button.Width; } } textbox.Padding = new Thickness(0, 0, padding, 0); return result; } ); column.SetCellBoundValue = false; } protected DynamicGridMaskColumn(DynamicGridColumn definition) : base(definition) { } }