From 0dc55ce5bf7918f185a3a9013d6923ba94e90d55 Mon Sep 17 00:00:00 2001 From: DevFromDownUnder Date: Wed, 20 Mar 2024 01:20:49 +1100 Subject: [PATCH] #373 Remove existing workaround Stop windows deleting and re-adding border, which was causing focus lose as elements were no longer attached to the current view --- src/UraniumUI.Material/Controls/InputField.cs | 27 ++++------- .../Controls/TextField.FocusingWorkaround.cs | 48 ------------------- 2 files changed, 8 insertions(+), 67 deletions(-) delete mode 100644 src/UraniumUI.Material/Controls/TextField.FocusingWorkaround.cs diff --git a/src/UraniumUI.Material/Controls/InputField.cs b/src/UraniumUI.Material/Controls/InputField.cs index fe999dec..fff360c1 100644 --- a/src/UraniumUI.Material/Controls/InputField.cs +++ b/src/UraniumUI.Material/Controls/InputField.cs @@ -197,32 +197,21 @@ private void InitializeBorder() return; } - border.Content = null; - this.Remove(border); - border = new Border + border.Padding = 0; + border.Stroke = BorderColor; + border.StrokeThickness = BorderThickness; + border.Background = InputBackground; + border.BackgroundColor = InputBackgroundColor; + border.StrokeDashOffset = 0; + border.StrokeShape = new RoundRectangle { - Padding = 0, - Stroke = BorderColor, - StrokeThickness = BorderThickness, - Background = InputBackground, - BackgroundColor = InputBackgroundColor, - StrokeDashOffset = 0, - StrokeShape = new RoundRectangle - { - CornerRadius = CornerRadius - }, - Content = rootGrid + CornerRadius = CornerRadius }; #endif border.StrokeDashArray = new DoubleCollection { calculatedFirstDash * 0.9 / BorderThickness, space / BorderThickness, perimeter, 0 }; -#if WINDOWS - this.Add(border); -#endif - UpdateState(); - border.StrokeThickness = BorderThickness; } protected virtual void UpdateState() diff --git a/src/UraniumUI.Material/Controls/TextField.FocusingWorkaround.cs b/src/UraniumUI.Material/Controls/TextField.FocusingWorkaround.cs deleted file mode 100644 index cb1f8984..00000000 --- a/src/UraniumUI.Material/Controls/TextField.FocusingWorkaround.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace UraniumUI.Material.Controls; -public partial class TextField -{ -#if WINDOWS // Workaround for https://github.com/enisn/UraniumUI/issues/373 - partial void AfterConstructor() - { - EntryView.HandlerChanged += (s, e) => - { - if (EntryView.Handler.PlatformView is Microsoft.UI.Xaml.Controls.TextBox view) - { - view.LosingFocus += (s, e) => - { - if (!canUnfocus) - { - e.TryCancel(); - } - }; - } - }; - } - - protected bool canUnfocus = true; - CancellationTokenSource unfocusCts = new(); - - protected override async void CheckAndShowValidations() - { - /* Disable focus for a short time to prevent unfocusing - * while validation adding to the layout */ - canUnfocus = false; - unfocusCts.Cancel(); - unfocusCts = new CancellationTokenSource(); - - base.CheckAndShowValidations(); - - await EnableFocusAfterAsync(500, unfocusCts.Token); - } - - async Task EnableFocusAfterAsync(int delayMs, CancellationToken cancellationToken) - { - await Task.Delay(delayMs); - if (cancellationToken.IsCancellationRequested) - { - return; - } - canUnfocus = true; - } -#endif -}