alexa
menu

WPF

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download

    Show / Hide Table of Contents

    Class SfSmartTextEditor

    Represents a text editor that provides inline or popup auto-suggestions while typing. Suggestions can be sourced from predefined user phrases or from an AI inference service, and can be accepted by pressing Tab or Right arrow.
    The following example shows how to use SfSmartTextEditor with a placeholder, inline suggestions, user-provided phrases for offline suggestions, and a command that triggers on every text change.

    • XAML
    <sync:SfSmartTextEditor x:Name="smartTextArea"
                            Placeholder="Please enter"
                            SuggestionDisplayMode="Inline"
                            UserRole="Support engineer responding to customer tickets"
                            UserPhrases="{Binding SuggestionPhrases}"
                            TextChangedCommand="{Binding OnEditorTextChanged}"/>
    public class MainViewModel
    {
        // Predefined phrases used for offline suggestions
        public List<string> SuggestionPhrases { get; } = new List<string>
        {
            "Hello! How can I help you?",
            "Thanks for reaching out.",
            "Could you share more details?",
            "We’re checking this for you.",
            "Please try restarting the app."
        };
    
        // Invoked on every text change
        public ICommand OnEditorTextChanged { get; }
    
        public MainViewModel()
        {
            OnEditorTextChanged = new RelayCommand(() =>
            {
                // Handle text change, analytics, logging, etc.
            });
        }
    }
    // Configure an AI chat client at the application level to enable AI suggestions.
    // If not configured, the control falls back to the UserPhrases list for offline suggestions.
    
    string azureApiKey = "<MENTION-YOUR-KEY>";
    Uri azureEndPoint = new Uri("<MENTION-YOUR-URL>");
    string deploymentName = "gpt-4o";
    
    // Create Azure OpenAI chat client (example)
    AzureOpenAIClient azureClient = new AzureOpenAIClient(azureEndPoint, new ApiKeyCredential(azureApiKey));
    IChatClient azureChatClient = azureClient.GetChatClient(deploymentName).AsIChatClient();
    
    // Register the client with Syncfusion AI services used by the editor
    SyncfusionAIExtension.Services.AddSingleton<IChatClient>(azureChatClient);
    SyncfusionAIExtension.ConfigureSyncfusionAIServices();
    Features - Inline or popup suggestions: Controlled by SuggestionDisplayMode. - Offline suggestions: Uses UserPhrases to suggest completions that start with the current input. - AI-powered suggestions: If an AI chat client is configured at the app level, the editor requests suggestions asynchronously. - Accepting suggestions: Press Tab or Right arrow to append the current suggestion to the editor text. - Placeholder: Shown when the editor is empty and not focused; controlled by Placeholder. - Debounced fetching: The editor waits briefly after typing before fetching suggestions to avoid excessive calls. - Command on text change: TextChangedCommand executes each time text changes, allowing MVVM-friendly handling.

    Behavior summary

    • If the caret is at the end of the text, the editor tries to show a suggestion.
    • If AI is configured and returns a suggestion, it is displayed; otherwise, the editor falls back to the best match from UserPhrases.
    • In Inline mode, the suggestion appears as ghost text following the current caret; in Popup mode, it appears near the caret.
    • Suggestions clear when the editor loses focus or text changes.

    Inheritance
    System.Object
    SfSmartTextEditor
    Implements
    System.IDisposable
    Namespace: Syncfusion.UI.Xaml.SmartComponents
    Assembly: Syncfusion.SfSmartComponents.Wpf.dll
    Syntax
    public class SfSmartTextEditor : TextBox, IDisposable

    Constructors

    SfSmartTextEditor()

    Initializes a new instance of the SfSmartTextEditor class.

    Declaration
    public SfSmartTextEditor()

    Fields

    PlaceholderProperty

    Identifies the Placeholder dependency property.

    Declaration
    public static readonly DependencyProperty PlaceholderProperty
    Field Value
    Type
    System.Windows.DependencyProperty

    PlaceholderStyleProperty

    Identifies the PlaceholderStyle dependency property.

    Declaration
    public static readonly DependencyProperty PlaceholderStyleProperty
    Field Value
    Type
    System.Windows.DependencyProperty

    SuggestionDisplayModeProperty

    Identifies the SuggestionDisplayMode dependency property.

    Declaration
    public static readonly DependencyProperty SuggestionDisplayModeProperty
    Field Value
    Type
    System.Windows.DependencyProperty

    SuggestionInlineStyleProperty

    Identifies the SuggestionInlineStyle dependency property.

    Declaration
    public static readonly DependencyProperty SuggestionInlineStyleProperty
    Field Value
    Type
    System.Windows.DependencyProperty

    SuggestionPopupStyleProperty

    Identifies the SuggestionPopupStyle dependency property.

    Declaration
    public static readonly DependencyProperty SuggestionPopupStyleProperty
    Field Value
    Type
    System.Windows.DependencyProperty

    SuggestionTextProperty

    Identifies the SuggestionText dependency property.

    Declaration
    public static readonly DependencyProperty SuggestionTextProperty
    Field Value
    Type
    System.Windows.DependencyProperty

    TextChangedCommandProperty

    Identifies the TextChangedCommand dependency property.

    Declaration
    public static readonly DependencyProperty TextChangedCommandProperty
    Field Value
    Type
    System.Windows.DependencyProperty

    UserPhrasesProperty

    Identifies the UserPhrases dependency property.

    Declaration
    public static readonly DependencyProperty UserPhrasesProperty
    Field Value
    Type
    System.Windows.DependencyProperty

    UserRoleProperty

    Identifies the UserRole dependency property.

    Declaration
    public static readonly DependencyProperty UserRoleProperty
    Field Value
    Type
    System.Windows.DependencyProperty

    Properties

    Placeholder

    Gets or sets the placeholder text displayed when the editor is empty and not focused.

    Declaration
    public string Placeholder { get; set; }
    Property Value
    Type
    System.String

    PlaceholderStyle

    Gets or sets a System.Windows.Style applied to the placeholder element in the control template.

    Declaration
    public Style PlaceholderStyle { get; set; }
    Property Value
    Type
    System.Windows.Style

    SuggestionDisplayMode

    Gets or sets the display mode for suggestions (inline or popup).

    Declaration
    public SuggestionDisplayMode SuggestionDisplayMode { get; set; }
    Property Value
    Type
    SuggestionDisplayMode

    SuggestionInlineStyle

    Gets or sets the style applied to the inline suggestion text displayed inside the SfSmartTextEditor control.

    Declaration
    public Style SuggestionInlineStyle { get; set; }
    Property Value
    Type
    System.Windows.Style

    SuggestionPopupStyle

    Gets or sets a System.Windows.Style applied to the suggestion popup in the control template.

    Declaration
    public Style SuggestionPopupStyle { get; set; }
    Property Value
    Type
    System.Windows.Style

    SuggestionText

    Gets the current suggestion text provided by the AI service. This may be shown inline or in a popup depending on SuggestionDisplayMode.

    Declaration
    public string SuggestionText { get; }
    Property Value
    Type
    System.String

    TextChangedCommand

    Gets or sets the command that is executed whenever the editor's text changes.

    Declaration
    public ICommand TextChangedCommand { get; set; }
    Property Value
    Type
    System.Windows.Input.ICommand

    UserPhrases

    Gets or sets a list of user-specific phrases to guide suggestion generation.

    Declaration
    public List<string> UserPhrases { get; set; }
    Property Value
    Type
    System.Collections.Generic.List<System.String>

    UserRole

    Gets or sets the role of the user interacting with the control. This value is sent to the AI service to contextualize suggestions.

    Declaration
    public string UserRole { get; set; }
    Property Value
    Type
    System.String

    Methods

    Dispose()

    Releases all resources used by the control.

    Declaration
    public void Dispose()

    Dispose(Boolean)

    Releases unmanaged resources and optionally managed resources.

    Declaration
    protected virtual void Dispose(bool isDisposing)
    Parameters
    Type Name Description
    System.Boolean isDisposing

    True to release both managed and unmanaged resources; otherwise false.

    OnApplyTemplate()

    Applies the control template and wires up template parts and event handlers.

    Declaration
    public override void OnApplyTemplate()

    Implements

    System.IDisposable
    Back to top Generated by DocFX
    Copyright © 2001 - 2026 Syncfusion Inc. All Rights Reserved