123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using Avalonia.Controls;
- using Avalonia.Input;
- using Avalonia.Interactivity;
- using Avalonia.Layout;
- using Avalonia.Media;
- using CommunityToolkit.Mvvm.Input;
- using DialogHostAvalonia;
- using InABox.Avalonia;
- using InABox.Avalonia.Components;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PRS.Avalonia.DigitalForms;
- partial class DFStringFieldControl : DigitalFormFieldControl<DFLayoutStringField, DFLayoutStringFieldProperties, string, string?>
- {
- private string? text;
- private TextBox? TextBox;
- private Button? Btn;
- private TextBlock? TextBlock;
- [NotNull]
- private string? Text
- {
- get => (Field.Properties.PopupEditor ? text : TextBox?.Text) ?? "";
- set
- {
- if (Field.Properties.PopupEditor)
- {
- text = value;
- TextBlock!.Text = value;
- }
- else if(TextBox is not null)
- {
- TextBox.Text = value;
- }
- }
- }
- public override void SetSerializedValue(string? value)
- {
- Text = value;
- }
- public override string? GetSerializedValue()
- {
- return Text;
- }
- protected override Control Create()
- {
- if (Field.Properties.PopupEditor)
- {
- var panel = new DockPanel();
- Btn = new Button { Content = "..." };
- Btn.Command = PopupCommand;
- TextBlock = new TextBlock();
- TextBlock.Classes.Add("DFStringFieldControl");
- DockPanel.SetDock(Btn, Dock.Left);
- DockPanel.SetDock(TextBlock, Dock.Right);
- panel.Children.Add(Btn);
- panel.Children.Add(TextBlock);
- return panel;
- }
- else
- {
- TextBox = new TextBox();
- TextBox.Text = Field.Properties.Default;
- TextBox.TextWrapping = Field.Properties.TextWrapping ? TextWrapping.Wrap : TextWrapping.NoWrap;
- TextBox.TextAlignment = TextAlignment.Left;
- TextBox.VerticalContentAlignment = VerticalAlignment.Center;
- TextBox.VerticalAlignment = VerticalAlignment.Stretch;
- TextBox.TextChanged += (sender, e) => ChangeField();
- return TextBox;
- }
- }
- public override void SetBackground(IBrush brush, bool defaultColour)
- {
- if (Field.Properties.PopupEditor)
- {
- Background = brush;
- }
- else
- {
- TextBox!.Background = brush;
- }
- }
- [RelayCommand]
- private async Task Popup()
- {
- var result = await Navigation.Popup<TextEditViewModel, string?>(x =>
- {
- x.Text = Text;
- x.Multiline = true;
- });
- if(result is not null)
- {
- Text = result;
- ChangeField();
- }
- }
- public override string GetValue() => Text;
- public override void SetValue(string? value) => Text = value;
- protected override bool IsEmpty() => string.IsNullOrWhiteSpace(Text);
- }
|