123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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<TEntity, TEditor> : DynamicGridEditorColumn<TEntity, TEditor, GridTemplateColumn>
- 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)
- {
- }
- }
|