Skip to content
Open
92 changes: 51 additions & 41 deletions src/Controls/samples/Controls.Sample/Pages/Controls/EntryPage.xaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<views:BasePage
x:Class="Maui.Controls.Sample.Pages.EntryPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Pages.EntryPage"
xmlns:controls="clr-namespace:Maui.Controls.Sample.Pages"
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base"
xmlns:viewmodels="clr-namespace:Maui.Controls.Sample.ViewModels"
xmlns:views="clr-namespace:Maui.Controls.Sample.Pages.Base"
Title="Entry">
<views:BasePage.Resources>
<ResourceDictionary>
Expand All @@ -15,12 +15,12 @@
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Pink"/>
<Setter Property="BackgroundColor" Value="Pink" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Yellow"/>
<Setter Property="BackgroundColor" Value="Yellow" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Disabled">
Expand All @@ -43,40 +43,50 @@
<VerticalStackLayout Padding="12">
<Button Margin="5" x:Name="ShowSoftInputAsyncButton" Clicked="ShowSoftInputAsyncButton_Clicked" Text="Show Soft Input for Placeholder Button" />
<Button Margin="5" x:Name="HideSoftInputAsyncButton" Clicked="HideSoftInputAsyncButton_Clicked" Text="Hide Soft Input" />
<Label
Text="Basic"
Style="{StaticResource Headline}" />
<Entry />
<VerticalStackLayout Spacing="4">
<Label
Text="Basic"
Style="{StaticResource Headline}" />
<Entry />
</VerticalStackLayout>
<VerticalStackLayout Spacing="4">
<Label
Text="Without Border"
Style="{StaticResource Headline}" />
<Entry
Text="Text"
BorderStyle="None" />
</VerticalStackLayout>
<Label
Text="Disabled"
Style="{StaticResource Headline}" />
<Entry
IsEnabled="False"/>
<Entry
IsEnabled="False" />
<Label
Text="Using TextColor"
Style="{StaticResource Headline}" />
<Entry
Text="Text"
TextColor="Purple"/>
TextColor="Purple" />
<Label
Text="Using TextColor (for the text color and the clear button color)"
Style="{StaticResource Headline}" />
<Entry
ClearButtonVisibility="WhileEditing"
Text="Text"
TextColor="Red"/>
TextColor="Red" />
<Label
Text="With Placeholder"
Style="{StaticResource Headline}" />
<Entry
x:Name="PlaceholderEntryItem"
Placeholder="Placeholder"/>
Placeholder="Placeholder" />
<Label
Text="Using PlaceholderColor"
Style="{StaticResource Headline}" />
<Entry
PlaceholderColor="Purple"
Placeholder="Placeholder"/>
Placeholder="Placeholder" />
<Label
Text="Password"
Style="{StaticResource Headline}" />
Expand All @@ -86,7 +96,7 @@
IsChecked="true" />
<Label
Text="Is Password"
VerticalOptions="Center"/>
VerticalOptions="Center" />
</HorizontalStackLayout>
<Entry
x:Name="pwdPassword"
Expand All @@ -99,53 +109,53 @@
Text="With Text"
Style="{StaticResource Headline}" />
<Entry
Text="Text"/>
Text="Text" />
<Label
Text="ClearButtonVisibility = Never"
Style="{StaticResource Headline}" />
<Entry
Text="Text"
ClearButtonVisibility="Never"/>
ClearButtonVisibility="Never" />
<Label
Text="ClearButtonVisibility = WhileEditing"
Style="{StaticResource Headline}" />
<Entry
Text="Text"
ClearButtonVisibility="WhileEditing"/>
ClearButtonVisibility="WhileEditing" />
<Label
Text="Read-only"
Style="{StaticResource Headline}" />
<Entry
Text="I am read only"
IsReadOnly="True"/>
IsReadOnly="True" />
<Label
Text="SpellCheck (True), TextPrediction (True)"
Style="{StaticResource Headline}" />
<Entry
Text="Whats new"
IsSpellCheckEnabled="True"
IsTextPredictionEnabled="True"/>
IsTextPredictionEnabled="True" />
<Label
Text="SpellCheck (False), TextPrediction (True)"
Style="{StaticResource Headline}" />
<Entry
Text="Whats new"
IsSpellCheckEnabled="False"
IsTextPredictionEnabled="True"/>
IsTextPredictionEnabled="True" />
<Label
Text="SpellCheck (True), TextPrediction (False)"
Style="{StaticResource Headline}" />
<Entry
Text="Whats new"
IsSpellCheckEnabled="True"
IsTextPredictionEnabled="False"/>
IsTextPredictionEnabled="False" />
<Label
Text="SpellCheck (False), TextPrediction (False)"
Style="{StaticResource Headline}" />
<Entry
Text="Whats new"
IsSpellCheckEnabled="False"
IsTextPredictionEnabled="False"/>
IsTextPredictionEnabled="False" />
<Label
Text="ReturnType (Search)"
Style="{StaticResource Headline}" />
Expand All @@ -156,47 +166,47 @@
Style="{StaticResource Headline}" />
<Entry
x:Name="ReturnTypeEntry"
TextChanged="OnReturnTypeEntryTextChanged"/>
TextChanged="OnReturnTypeEntryTextChanged" />
<Label
Text="Return Command"
Style="{StaticResource Headline}" />
<Entry
ReturnCommand="{Binding ReturnCommand}"
ReturnCommandParameter="ReturnCommandParameter"/>
ReturnCommandParameter="ReturnCommandParameter" />
<Label
Text="Focus"
Style="{StaticResource Headline}" />
<Entry
Focused="OnEntryFocused"/>
Focused="OnEntryFocused" />
<Label
Text="Unfocus"
Style="{StaticResource Headline}" />
<Entry
Unfocused="OnEntryUnfocused"/>
Unfocused="OnEntryUnfocused" />
<Label
Text="Completed"
Style="{StaticResource Headline}" />
<Entry
Completed="OnEntryCompleted"/>
Completed="OnEntryCompleted" />
<Label
Text="BackgroundColor"
Style="{StaticResource Headline}" />
<Entry
Text="BackgroundColor"
BackgroundColor="Orange"/>
BackgroundColor="Orange" />
<Label
Text="BackgroundColor"
Style="{StaticResource Headline}" />
<Entry
x:Name="BackgroundColorEntry"/>
x:Name="BackgroundColorEntry" />
<Button
x:Name="UpdateBackgroundColorButton"
Text="Update Background Color"
Clicked="OnUpdateBackgroundColorButtonClicked"/>
Clicked="OnUpdateBackgroundColorButtonClicked" />
<Button
x:Name="ClearBackgroundColorButton"
Text="Clear Background Color"
Clicked="OnClearBackgroundColorButtonClicked"/>
Clicked="OnClearBackgroundColorButtonClicked" />
<Label
Text="Background"
Style="{StaticResource Headline}" />
Expand All @@ -215,15 +225,15 @@
Text="Background"
Style="{StaticResource Headline}" />
<Entry
x:Name="BackgroundEntry"/>
x:Name="BackgroundEntry" />
<Button
x:Name="UpdateBackgroundButton"
Text="Update Background"
Clicked="OnUpdateBackgroundButtonClicked"/>
Clicked="OnUpdateBackgroundButtonClicked" />
<Button
x:Name="ClearBackgroundButton"
Text="Clear Background"
Clicked="OnClearBackgroundButtonClicked"/>
Clicked="OnClearBackgroundButtonClicked" />
<Label
Text="Updating Background using VisualStates"
Style="{StaticResource Headline}" />
Expand All @@ -238,7 +248,7 @@
Style="{StaticResource Headline}" />
<Entry
Text="123"
Keyboard="Numeric"/>
Keyboard="Numeric" />
<Label
Text="HorizontalTextAlignment"
Style="{StaticResource Headline}" />
Expand All @@ -251,30 +261,30 @@
<Entry
VerticalTextAlignment="End"
Text="This should be on the bottom"
HeightRequest="100"/>
HeightRequest="100" />
<HorizontalStackLayout>
<Label
x:Name="lblCursor"
Text="CursorPosition = 4"
Style="{StaticResource Headline}" />
<Slider x:Name="sldCursorPosition" ValueChanged="OnSlideCursorPositionValueChanged" WidthRequest="100"/>
<Slider x:Name="sldCursorPosition" ValueChanged="OnSlideCursorPositionValueChanged" WidthRequest="100" />
</HorizontalStackLayout>
<Entry
x:Name="entryCursor"
Text="Cursor"
CursorPosition="4"/>
CursorPosition="4" />
<HorizontalStackLayout>
<Label
x:Name="lblSelection"
Text="SelectionLength = 4"
Style="{StaticResource Headline}" />
<Slider x:Name="sldSelection" ValueChanged="OnSlideSelectionValueChanged" WidthRequest="100"/>
<Slider x:Name="sldSelection" ValueChanged="OnSlideSelectionValueChanged" WidthRequest="100" />
</HorizontalStackLayout>
<Entry
x:Name="entrySelection"
Text="Selection"
CursorPosition="2"
SelectionLength="4"/>
SelectionLength="4" />
<Label
Text="Platform Specific (Search ImeOptions)"
Style="{StaticResource Headline}" />
Expand Down
14 changes: 14 additions & 0 deletions src/Controls/src/Core/Entry/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public partial class Entry : InputView, ITextAlignmentElement, IEntryController,
/// </summary>
public static readonly BindableProperty IsPasswordProperty = BindableProperty.Create(nameof(IsPassword), typeof(bool), typeof(Entry), default(bool));

/// <summary>
/// Backing store for the <see cref="BorderStyle"/> property.
/// </summary>
public static readonly BindableProperty BorderStyleProperty = BindableProperty.Create(nameof(BorderStyle), typeof(BorderStyle), typeof(Entry), BorderStyle.Default);

/// <inheritdoc cref="InputView.TextProperty"/>
public new static readonly BindableProperty TextProperty = InputView.TextProperty;

Expand Down Expand Up @@ -125,6 +130,15 @@ public bool IsPassword
set { SetValue(IsPasswordProperty, value); }
}

/// <summary>
/// Gets or sets the border style of the Entry. This is a bindable property.
/// </summary>
public BorderStyle BorderStyle
{
get { return (BorderStyle)GetValue(BorderStyleProperty); }
set { SetValue(BorderStyleProperty, value); }
}

/// <summary>
/// Determines what the return key on the on-screen keyboard should look like. This is a bindable property.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#nullable enable
Microsoft.Maui.Controls.Entry.BorderStyle.get -> Microsoft.Maui.BorderStyle
Microsoft.Maui.Controls.Entry.BorderStyle.set -> void
~static readonly Microsoft.Maui.Controls.Entry.BorderStyleProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
*REMOVED*~static readonly Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.DefaultForegroundColor -> Microsoft.Maui.Graphics.Color
*REMOVED*~static readonly Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer.DefaultTitleColor -> Microsoft.Maui.Graphics.Color
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#nullable enable
#nullable enable
Microsoft.Maui.Controls.Entry.BorderStyle.get -> Microsoft.Maui.BorderStyle
Microsoft.Maui.Controls.Entry.BorderStyle.set -> void
~static readonly Microsoft.Maui.Controls.Entry.BorderStyleProperty -> Microsoft.Maui.Controls.BindableProperty
Microsoft.Maui.Controls.AppThemeBinding
Microsoft.Maui.Controls.AppThemeBinding.AppThemeBinding() -> void
~Microsoft.Maui.Controls.AppThemeBinding.Dark.get -> object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#nullable enable
#nullable enable
Microsoft.Maui.Controls.Entry.BorderStyle.get -> Microsoft.Maui.BorderStyle
Microsoft.Maui.Controls.Entry.BorderStyle.set -> void
~static readonly Microsoft.Maui.Controls.Entry.BorderStyleProperty -> Microsoft.Maui.Controls.BindableProperty
Microsoft.Maui.Controls.AppThemeBinding
Microsoft.Maui.Controls.AppThemeBinding.AppThemeBinding() -> void
~Microsoft.Maui.Controls.AppThemeBinding.Dark.get -> object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#nullable enable
Microsoft.Maui.Controls.Entry.BorderStyle.get -> Microsoft.Maui.BorderStyle
Microsoft.Maui.Controls.Entry.BorderStyle.set -> void
~static readonly Microsoft.Maui.Controls.Entry.BorderStyleProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
Microsoft.Maui.Controls.AppThemeBinding
Microsoft.Maui.Controls.AppThemeBinding.AppThemeBinding() -> void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#nullable enable
Microsoft.Maui.Controls.Entry.BorderStyle.get -> Microsoft.Maui.BorderStyle
Microsoft.Maui.Controls.Entry.BorderStyle.set -> void
~static readonly Microsoft.Maui.Controls.Entry.BorderStyleProperty -> Microsoft.Maui.Controls.BindableProperty
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
Microsoft.Maui.Controls.AppThemeBinding
Microsoft.Maui.Controls.AppThemeBinding.AppThemeBinding() -> void
Expand Down
5 changes: 4 additions & 1 deletion src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#nullable enable
#nullable enable
Microsoft.Maui.Controls.Entry.BorderStyle.get -> Microsoft.Maui.BorderStyle
Microsoft.Maui.Controls.Entry.BorderStyle.set -> void
~static readonly Microsoft.Maui.Controls.Entry.BorderStyleProperty -> Microsoft.Maui.Controls.BindableProperty
Microsoft.Maui.Controls.AppThemeBinding
Microsoft.Maui.Controls.AppThemeBinding.AppThemeBinding() -> void
~Microsoft.Maui.Controls.AppThemeBinding.Dark.get -> object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#nullable enable
#nullable enable
Microsoft.Maui.Controls.Entry.BorderStyle.get -> Microsoft.Maui.BorderStyle
Microsoft.Maui.Controls.Entry.BorderStyle.set -> void
~static readonly Microsoft.Maui.Controls.Entry.BorderStyleProperty -> Microsoft.Maui.Controls.BindableProperty
~Microsoft.Maui.Controls.BackButtonBehavior.AccessibilityLabel.get -> string
~Microsoft.Maui.Controls.BackButtonBehavior.AccessibilityLabel.set -> void
~Microsoft.Maui.Controls.BaseShellItem.BadgeColor.get -> Microsoft.Maui.Graphics.Color
Expand Down
5 changes: 5 additions & 0 deletions src/Core/src/Core/IEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public interface IEntry : IView, ITextInput, ITextAlignment
/// </summary>
bool IsPassword { get; }

/// <summary>
/// Gets a value that controls the border style of the Entry.
/// </summary>
BorderStyle BorderStyle { get; }

/// <summary>
/// Gets an enumeration value that controls the appearance of the return button.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Core/src/Handlers/Entry/EntryHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public static void MapIsPassword(IEntryHandler handler, IEntry entry)

handler.PlatformView?.UpdateIsPassword(entry);
}

public static void MapBorderStyle(IEntryHandler handler, IEntry entry)
{
handler.UpdateValue(nameof(IEntry.Text));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MapBorderStyle calls handler.UpdateValue(nameof(IEntry.Text)) before applying the border-only change. On Android MapText -> UpdateText reassigns EditText.Text and calls SetSelection(Text.Length) (EditTextExtensions.cs:29), so toggling BorderStyle while the user is editing moves the caret to the end and re-runs text-side effects even though no text changed. iOS and Windows MapBorderStyle don't do this -- UpdateBorderStyle only touches BackgroundTintList, so this line is unnecessary (it appears copied from the MapIsPassword/InputType pattern, where it is justified). Remove it, and consider a regression test asserting CursorPosition/SelectionLength are preserved across a BorderStyle change.


handler.PlatformView?.UpdateBorderStyle(entry);
}

public static void MapHorizontalTextAlignment(IEntryHandler handler, IEntry entry) =>
handler.PlatformView?.UpdateHorizontalTextAlignment(entry);
Expand Down
Loading
Loading