forked from dotnet/maui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIssue19109.cs
More file actions
62 lines (55 loc) · 1.98 KB
/
Issue19109.cs
File metadata and controls
62 lines (55 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 19109, "CursorPosition Property Not Applied Correctly to Entry Control on iOS Platform", PlatformAffected.iOS)]
public partial class Issue19109: ContentPage
{
Entry entry;
public Issue19109()
{
entry = new Entry
{
Text = "Entry 123",
CursorPosition = 5,
Placeholder = "Focus this entry to check if the cursor position is set correctly.",
ReturnType = ReturnType.Next,
AutomationId = "EntryControl"
};
var button = new Button
{
Text = "Focus Entry",
AutomationId = "FocusButton"
};
var label = new Label
{
Text = "Cursor Position: 5",
FontSize = 16,
TextColor = Colors.Black,
HorizontalOptions = LayoutOptions.Center
};
var rangeLabel = new Label
{
AutomationId = "RangeLabel",
Text = "Range not set yet",
HorizontalOptions = LayoutOptions.Center
};
button.Clicked += (sender, e) =>
{
entry.Focus();
#if IOS
if (entry.Handler?.PlatformView is UIKit.UITextField textField && textField.SelectedTextRange != null)
{
rangeLabel.Text = $"Start={textField.GetOffsetFromPosition(textField.BeginningOfDocument, textField.SelectedTextRange.Start)}, " +
$"End={textField.GetOffsetFromPosition(textField.BeginningOfDocument, textField.SelectedTextRange.End)}";
}
#endif
};
Content = new StackLayout
{
Children = { entry, button, label, rangeLabel },
Padding = new Thickness(20),
Spacing = 10
};
}
}
}