From 24b25c4b9243e6bec43b57c4a9c55700c74079f7 Mon Sep 17 00:00:00 2001 From: KB Bot Date: Tue, 2 Dec 2025 12:17:00 +0000 Subject: [PATCH 1/2] Added new kb article change-entry-cursor-color-dotnet-maui --- .../change-entry-cursor-color-dotnet-maui.md | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 knowledge-base/change-entry-cursor-color-dotnet-maui.md diff --git a/knowledge-base/change-entry-cursor-color-dotnet-maui.md b/knowledge-base/change-entry-cursor-color-dotnet-maui.md new file mode 100644 index 000000000..c446a9242 --- /dev/null +++ b/knowledge-base/change-entry-cursor-color-dotnet-maui.md @@ -0,0 +1,106 @@ +--- +title: Changing Entry Cursor Color on Android and iOS +description: Learn how to change the cursor color of the Entry control on Android and on iOS to match the application's input field styling. +type: how-to +page_title: Adjusting Cursor Color for Entry Control in UI for .NET MAUI +meta_title: Adjusting Cursor Color for Entry Control in UI for .NET MAUI +slug: change-entry-cursor-color-dotnet-maui +tags: entry, ui for .net maui, cursor color, android, radtextinput, handlerchanged, native customization +res_type: kb +--- + +## Environment + +| Version | Product | Author | +| --- | --- | ---- | +| 8.0.0 and above | Telerik UI for .NET MAUI Entry | [Dobrinka Yordanova](https://www.telerik.com/blogs/author/dobrinka-yordanova) | + +## Description + +I am trying to change the cursor color of the [UI for .NET MAUI Entry ](https://www.telerik.com/maui-ui/documentation/controls/entry/overview) control on Android and on iOS to match the color of other input fields in the application. However, the available documentation for customizing the cursor is for versions 5.2.0 to 7.0.0 and is incompatible with the current version. Since version 8.0.0, the control uses `RadTextInput` internally instead of `RadEntry`, which requires different logic for cursor customization. + +This knowledge base article also answers the following questions: +- How to update Entry cursor color on mobile? +- How to handle breaking changes for cursor customization in Entry after version 8.0.0? +- How to apply native logic to change cursor color in Entry control? + +## Solution + +To modify the cursor color in the Entry control, follow these steps: + +1. Handle the `Loaded` event of the Entry control to locate the internal `RadTextInput` control and apply the necessary native logic. +2. Use the `Handler` property of `RadTextInput` to update the cursor color for Android and iOS. + +```csharp +private void entry_Loaded(object sender, EventArgs e) +{ + var textInput = ChildOfType(this.entry); + if (textInput != null) + { + var handler = textInput.Handler; + if (handler == null) + { + textInput.HandlerChanged += this.OnTextInputHandlerChanged; + } + else + { + this.UpdateNativeElement(handler); + } + } +} + +private void OnTextInputHandlerChanged(object sender, EventArgs e) +{ + var textInput = (RadTextInput)sender; + this.UpdateNativeElement(textInput.Handler); + textInput.HandlerChanged -= this.OnTextInputHandlerChanged; +} + +private void UpdateNativeElement(IViewHandler handler) +{ + var nativeEntry = handler.PlatformView as Telerik.Maui.Platform.RadMauiTextInput; + if (nativeEntry != null) + { +#if ANDROID + nativeEntry.TextCursorDrawable?.SetColorFilter(new Android.Graphics.PorterDuffColorFilter(Android.Graphics.Color.Red, Android.Graphics.PorterDuff.Mode.Darken)); +#elif __IOS__ + nativeEntry.TintColor = UIKit.UIColor.Red; +#endif + } +} + +internal static T ChildOfType(View visualElement) where T : View +{ + if (visualElement == null) + { + return null; + } + + foreach (var item in VisualTreeElementExtensions.GetVisualTreeDescendants(visualElement)) + { + if (item is T targetElement) + { + return targetElement; + } + } + + return null; +} +``` + +3. Add sample Entry definition in XAML: + +```xaml + + + +``` + + +## See Also + +- [Breaking Changes in UI for .NET MAUI 8.0.0](https://www.telerik.com/maui-ui/documentation/upgrade/breaking-changes/8-0-0) +- [Feature Request: Change Cursor Color in Entry](https://feedback.telerik.com/maui/1609886-entry-provide-an-option-to-change-the-cursor-caret-color) +- [UI for .NET MAUI Entry Overview](https://www.telerik.com/maui-ui/components/entry/overview) + From 330badd92b68c83853f7230671fdfef1aea356bb Mon Sep 17 00:00:00 2001 From: Didi Yordanova <39412212+didiyordanova@users.noreply.github.com> Date: Wed, 3 Dec 2025 14:29:04 +0200 Subject: [PATCH 2/2] Update knowledge-base/change-entry-cursor-color-dotnet-maui.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- knowledge-base/change-entry-cursor-color-dotnet-maui.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knowledge-base/change-entry-cursor-color-dotnet-maui.md b/knowledge-base/change-entry-cursor-color-dotnet-maui.md index c446a9242..fa30cdf01 100644 --- a/knowledge-base/change-entry-cursor-color-dotnet-maui.md +++ b/knowledge-base/change-entry-cursor-color-dotnet-maui.md @@ -93,7 +93,7 @@ internal static T ChildOfType(View visualElement) where T : View ```xaml + Loaded="entry_Loaded" /> ```