diff --git a/src/Controls/src/Core/InputView/InputView.cs b/src/Controls/src/Core/InputView/InputView.cs index 57b85ccf0efc..7aee0f59b82b 100644 --- a/src/Controls/src/Core/InputView/InputView.cs +++ b/src/Controls/src/Core/InputView/InputView.cs @@ -274,6 +274,27 @@ string ITextInput.Text set => SetValue(TextProperty, value, SetterSpecificity.FromHandler); } + private protected override void OnBindablePropertySet(BindableProperty property, object original, object value, bool changed, bool willFirePropertyChanged) + { + base.OnBindablePropertySet(property, original, value, changed, willFirePropertyChanged); + + // Note: these properties will always raise change events when set. On platforms like WinUI we + // need to always push the xplat -> native value flow in scenarios such as "select all text on focus". If we + // don't do this the native control will handle the input event and move the cursor after we set the selection + // length/cursor position, which is not the desired behavior. + if (!changed) + { + if (property.PropertyName == nameof(CursorPosition)) + { + Handler?.UpdateValue(nameof(CursorPosition)); + } + if (property.PropertyName == nameof(SelectionLength)) + { + Handler?.UpdateValue(nameof(SelectionLength)); + } + } + } + private protected override string GetDebuggerDisplay() { return $"Text = {Text}, {base.GetDebuggerDisplay()}"; diff --git a/src/Controls/tests/TestCases.HostApp/Issues/EntrySelectionTest.xaml b/src/Controls/tests/TestCases.HostApp/Issues/EntrySelectionTest.xaml new file mode 100644 index 000000000000..9f9babfef628 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/EntrySelectionTest.xaml @@ -0,0 +1,19 @@ + + + + +