Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit dac0928

Browse files
Fix an issue with the CursorPosition of the MaterialEntry
1 parent 37bc710 commit dac0928

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/MaterialDesignControls/Controls/MaterialEntry.xaml.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ public int MaxLength
247247
set { SetValue(MaxLengthProperty, value); }
248248
}
249249

250+
public static readonly BindableProperty CursorPositionProperty =
251+
BindableProperty.Create(nameof(CursorPosition), typeof(int), typeof(MaterialEntry), defaultValue: 0);
252+
253+
public int CursorPosition
254+
{
255+
get { return (int)GetValue(CursorPositionProperty); }
256+
set { SetValue(CursorPositionProperty, value); }
257+
}
258+
250259
public override bool IsControlFocused
251260
{
252261
get { return txtEntry.IsFocused; }
@@ -331,6 +340,10 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
331340
this.txtEntry.MaxLength = this.MaxLength;
332341
break;
333342

343+
case nameof(this.CursorPosition):
344+
this.txtEntry.CursorPosition = this.CursorPosition;
345+
break;
346+
334347
case nameof(IsPassword):
335348
this.txtEntry.IsPassword = IsPassword;
336349
SetShowPasswordIconIsVisible();
@@ -473,7 +486,12 @@ private void HandleFocusChange(object sender, FocusEventArgs e)
473486
base.SetFocusChange(lblLabel, frmContainer, bxvLine);
474487

475488
if (IsControlFocused)
489+
{
476490
Focused?.Invoke(this, e);
491+
492+
var textInsideInput = txtEntry.Text;
493+
txtEntry.CursorPosition = string.IsNullOrEmpty(textInsideInput) ? 0 : textInsideInput.Length;
494+
}
477495
else
478496
Unfocused?.Invoke(this, e);
479497
}

0 commit comments

Comments
 (0)