Skip to main content

AutoCompleteEditBase.Text Property

Gets or sets the edit box text. This is a bindable property.

Namespace: DevExpress.Maui.Editors

Assembly: DevExpress.Maui.Editors.dll

NuGet Package: DevExpress.Maui.Editors

Declaration

public string Text { get; set; }

Property Value

Type Description
String

The text in the edit box.

Example

The code below handles the TextChanged event to supply suggestions.

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:dxe="clr-namespace:DevExpress.Maui.Editors;assembly=DevExpress.Maui.Editors"
             xmlns:local="clr-namespace:DemoCenter.Forms.Views"
             x:Class="DemoCenter.Forms.Views.AutoCompleteEditView">
    <ContentPage.BindingContext>
        <local:AutoCompleteEditViewModel/>
    </ContentPage.BindingContext>
    <ContentPage.Content>
        <dxe:AutoCompleteEdit TextChanged="AutoCompleteEdit_TextChanged" 
                              ItemsSource="{Binding ItemsSource}"
                              LoadingProgressMode="Manual"/>
    </ContentPage.Content>
</ContentPage>
using System;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using DevExpress.Maui.Editors;

namespace DemoCenter.Forms.Views {
    // View
    public partial class AutoCompleteEditView : ContentPage {
        private void AutoCompleteEdit_TextChanged(object sender, DevExpress.Maui.Editors.AutoCompleteEditTextChangedEventArgs e) {
            AutoCompleteEdit edit = sender as AutoCompleteEdit;
            AutoCompleteEditViewModel viewModel = edit.BindingContext as AutoCompleteEditViewModel;
            if (e.Reason == DevExpress.Maui.Editors.AutoCompleteEditTextChangeReason.UserInput) {
                edit.IsLoadingInProgress = true;
                Task.Factory.StartNew(new Action(() => {
                    Thread.Sleep(3000);
                    Dispatcher.Dispatch(new Action(() => {
                        viewModel.ItemsSource = Model.Queries.Where(i => i.Contains(edit.Text)).ToList<string>();
                        edit.IsLoadingInProgress = false;
                    }));
                }));
            }
        }
    }
    // View Model
    public class AutoCompleteEditViewModel : INotifyPropertyChanged {
        List<string> itemsSource = new List<string>();
        public List<string> ItemsSource { get { return itemsSource; } set { itemsSource = value; OnPropertyChanged(nameof(ItemsSource)); } }

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName) {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    // Model
    class Model {
        public static List<string> Queries = new List<string>();
        static Model() {
            Queries.Add("California");
            Queries.Add("Colorado");
            Queries.Add("Connecticut");
        }
    }
}
See Also