Back to Devexpress

TextEditBase.Text Property

maui-devexpress-dot-maui-dot-editors-dot-texteditbase-83621c35.md

latest7.3 KB
Original Source

TextEditBase.Text Property

Gets or sets the text entered in the editor. This is a bindable property.

Namespace : DevExpress.Maui.Editors

Assembly : DevExpress.Maui.Editors.dll

NuGet Package : DevExpress.Maui.Editors

Declaration

csharp
public string Text { get; set; }

Property Value

TypeDescription
String

The text entered in the editor.

|

Remarks

Use the Text property to get or set text entered in the editor box.

Use the TextChangedCommand and TextChangedCommandParameter properties to specify the command executed when text changes. You can also handle the TextChanged event that fires when text changes.

After a user has finished the input and tapped the return button on the keyboard, the Completed event occurs.
To prevent users from entering text in the editor, set the IsReadOnly property to true.

Text Appearance

Use the following properties to customize the text appearance and alignment:

This example shows how to change the input text color and adjust font settings:

xml
<dxe:TextEdit Text="Input text"
              TextColor="Blue"
              TextFontAttributes="Italic"
              TextFontSize="18"/>

Custom Fonts

To apply a custom font, add the font file to your solution, and then assign it to the editor’s TextFontFamily property.

This example shows how to apply the Verdana font.

  1. Add the font file to your platform-specific projects:

  2. In the App.xaml file, add the following lines to the ResourceDictionary section:

  3. Set the TextFontFamily property to the key defined for the custom font:

Note

The TextFontAttributes property affects the default font only. If you need to apply a bold or an italic custom font, use the corresponding font style file as described above.

Input Validation

You can use the Text property to obtain the text entered in the editor and validate it.

This example shows how to validate the TextEdit‘s input text on a button tap. If no text is entered, the editor shows an error message.

  1. Specify the TextEdit instance’s name and a message that the editor should display when the error is detected.
xml
<dxe:TextEdit x:Name="loginEditor" 
              ErrorText="Login cannot be empty!"/>
  1. Subscribe to the button’s Clicked event.

  2. In the event handler, set the editor’s HasError property to true if the Text string is null or empty.

Text Selection

Use the following properties to manage the cursor position and text selection:

|

Property

|

Description

| | --- | --- | |

CursorPosition

|

Gets or sets the cursor position. This is a bindable property.

| |

SelectionStart

|

Gets a character index at which the selection starts. This is a bindable property.

| |

SelectionLength

|

Gets the number of selected characters. This is a bindable property.

|

You can also use the SelectAll(), SetSelection(Int32), and SetSelection(Int32, Int32) methods to select text.

Clear Icon

An editor can display a ‘clear’ icon that allows users to remove text that was entered. Use the following properties to manage the ‘clear’ icon:

|

Property

|

Description

| | --- | --- | |

ClearIconVisibility

|

Gets or sets whether the clear icon is displayed. This is a bindable property.

| |

ClearIcon

|

Gets or sets the clear icon image. This is a bindable property.

| |

ClearIconClicked
ClearIconCommand

|

Add a custom action to the ‘clear’ icon. Occurs when a user taps the clear icon.

| |

ClearIconColor

|

Gets or sets the color of the clear icon. This is a bindable property.

|

Assistive Elements

You can also optionally specify Prefix and Suffix that are shown before and after the input text (TextEdit), and add the following assistive text elements that provide additional information about text entered in the editor:

  • LabelText - the editor’s label;
  • PlaceholderText - the placeholder displayed within the editor box prior to user text input;
  • HelpText - the help text displayed below the editor box;
  • ErrorText - the error message displayed below the editor box in an error state.

See Also

TextEditBase Class

TextEditBase Members

DevExpress.Maui.Editors Namespace