Skip to content

Commit

Permalink
Add SelectionHighlightColor to TextField
Browse files Browse the repository at this point in the history
  • Loading branch information
enisn committed Mar 20, 2024
1 parent c8bc1ec commit d469162
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
11 changes: 11 additions & 0 deletions src/UraniumUI.Material/Controls/TextField.BindableProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Windows.Input;
using UraniumUI.Resources;
using UraniumUI.Material.Extensions;

namespace UraniumUI.Material.Controls;

Expand Down Expand Up @@ -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)
);
}
22 changes: 8 additions & 14 deletions src/UraniumUI.Material/Controls/TextField.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/UraniumUI.Material/Resources/StyleResource.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@

<Style TargetType="c:TextField" BaseResourceKey="InputFieldBaseStyle" CanCascade="True">
<Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource OnBackground}, Dark={StaticResource OnBackgroundDark}}" />
<Setter Property="SelectionHighlightColor" Value="{StaticResource Primary}" />
</Style>

<Style TargetType="c:AutoCompleteTextField" BaseResourceKey="InputFieldBaseStyle" CanCascade="True">
Expand Down

0 comments on commit d469162

Please sign in to comment.