コード例 #1
0
        public static UITextRange GetTextRange(this IUITextInput textInput, int start, int end)
        {
            if (textInput?.BeginningOfDocument == null)
            {
                return(null);
            }

            var from = textInput.GetPosition(textInput.BeginningOfDocument, start);
            var to   = textInput.GetPosition(textInput.BeginningOfDocument, end);

            if (from == null || to == null)
            {
                return(null);
            }

            return(textInput.GetTextRange(from, to));
        }
コード例 #2
0
ファイル: TextInputExtensions.cs プロジェクト: Glepooek/maui
        internal static void SetTextRange(this IUITextInput platformView, int start, int selectedTextLength)
        {
            int end = start + selectedTextLength;

            // Let's be sure we have positive positions
            start = Math.Max(start, 0);
            end   = Math.Max(end, 0);

            // Switch start and end positions if necessary
            start = Math.Min(start, end);
            end   = Math.Max(start, end);

            var startPosition = platformView.GetPosition(platformView.BeginningOfDocument, start);
            var endPosition   = platformView.GetPosition(platformView.BeginningOfDocument, end);

            platformView.SelectedTextRange = platformView.GetTextRange(startPosition, endPosition);
        }