From d4691623357a0ee606c6701a2ddf0bb3d4b9633d Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Wed, 20 Mar 2024 15:23:40 +0300 Subject: [PATCH] Add SelectionHighlightColor to TextField --- .../Controls/TextField.BindableProperties.cs | 11 ++++++++++ src/UraniumUI.Material/Controls/TextField.cs | 22 +++++++------------ .../Resources/StyleResource.xaml | 1 + 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/UraniumUI.Material/Controls/TextField.BindableProperties.cs b/src/UraniumUI.Material/Controls/TextField.BindableProperties.cs index 38cdb1e0..1a5db55d 100644 --- a/src/UraniumUI.Material/Controls/TextField.BindableProperties.cs +++ b/src/UraniumUI.Material/Controls/TextField.BindableProperties.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Windows.Input; using UraniumUI.Resources; +using UraniumUI.Material.Extensions; namespace UraniumUI.Material.Controls; @@ -177,4 +178,14 @@ public partial class TextField defaultValue: Entry.HorizontalTextAlignmentProperty.DefaultValue, propertyChanged: (bindable, oldValue, newValue) => (bindable as TextField).EntryView.HorizontalTextAlignment = (TextAlignment)newValue ); + + public Color SelectionHighlightColor { get => (Color)GetValue(SelectionHighlightColorProperty); set => SetValue(SelectionHighlightColorProperty, value); } + + public static readonly BindableProperty SelectionHighlightColorProperty = BindableProperty.Create( + nameof(SelectionHighlightColor), + typeof(Color), + typeof(TextField), + defaultValue: EntryProperties.SelectionHighlightColorProperty.DefaultValue, + propertyChanged: (bindable, oldValue, newValue) => EntryProperties.SetSelectionHighlightColor(bindable, (Color)newValue) + ); } \ No newline at end of file diff --git a/src/UraniumUI.Material/Controls/TextField.cs b/src/UraniumUI.Material/Controls/TextField.cs index 2e12cc45..9e1d38fb 100644 --- a/src/UraniumUI.Material/Controls/TextField.cs +++ b/src/UraniumUI.Material/Controls/TextField.cs @@ -1,7 +1,5 @@ -#if WINDOWS -using Microsoft.Maui.Platform; -#endif -using Plainer.Maui.Controls; +using Plainer.Maui.Controls; +using UraniumUI.Material.Extensions; using UraniumUI.Pages; using UraniumUI.Resources; using UraniumUI.Views; @@ -63,16 +61,6 @@ public TextField() protected override void OnHandlerChanged() { base.OnHandlerChanged(); -#if WINDOWS - if (EntryView.Handler.PlatformView is Microsoft.UI.Xaml.Controls.TextBox textBox) - { - textBox.SelectionHighlightColor = new Microsoft.UI.Xaml.Media.SolidColorBrush(ColorResource.GetColor("Primary", "PrimaryDark", Colors.Purple).ToWindowsColor()); - textBox.BorderThickness = new Microsoft.UI.Xaml.Thickness(0); - - textBox.Style = null; - } -#endif - if (Handler is null) { EntryView.TextChanged -= EntryView_TextChanged; @@ -82,9 +70,15 @@ protected override void OnHandlerChanged() { EntryView.TextChanged += EntryView_TextChanged; EntryView.Completed += EntryView_Completed; + ApplyAttachedProperties(); } } + protected virtual void ApplyAttachedProperties() + { + EntryProperties.SetSelectionHighlightColor(EntryView, SelectionHighlightColor); + } + private void EntryView_TextChanged(object sender, TextChangedEventArgs e) { if (string.IsNullOrEmpty(e.OldTextValue) || string.IsNullOrEmpty(e.NewTextValue)) diff --git a/src/UraniumUI.Material/Resources/StyleResource.xaml b/src/UraniumUI.Material/Resources/StyleResource.xaml index 825d73ef..3ac82eef 100644 --- a/src/UraniumUI.Material/Resources/StyleResource.xaml +++ b/src/UraniumUI.Material/Resources/StyleResource.xaml @@ -309,6 +309,7 @@