We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to handle focus events of the RibbonTextBox in WPF Ribbon control?

Platform: WPF |
Control: Ribbon |
Published Date: May 6, 2015 |
Last Revised Date: April 13, 2021

You can handle the focus events by using the GotKeyboardFocus and PreviewMouseLeftButtonDown events of RibbonTextBox in WPF Ribbon control. In the following example, the Focus of the RibbonTextBox has been changed similar to the search bar of the Internet Explorer. That means, when the TextBox is selected, the text gets highlighted and on the second click you can enter the text.


<syncfusion:RibbonWindow x:Class="Ribbon_131602.MainWindow"
        Title="MainWindow" Height="350" Width="525"
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        <syncfusion:Ribbon Name="MyRibbon" BackStageCornerImageVisibility="Collapsed"
            <syncfusion:RibbonTab Caption="TextFocus" syncfusion:Ribbon.KeyTip="E">
                <syncfusion:RibbonBar Header="FocusBar">
                    <syncfusion:RibbonTextBox Text="Simple text" x:Name="Text1" />
                    <syncfusion:RibbonTextBox Text="Focus Text" x:Name="Text2" GotKeyboardFocus="Text2_GotKeyboardFocus" PreviewMouseLeftButtonDown="Text2_PreviewMouseLeftButtonDown"/>
                    <syncfusion:RibbonTextBox Text="Simple text" x:Name="Text3" />
        <Grid Grid.Row="1">
            <RichTextBox Margin="12">
                        In this sample, we have added 3 RibbonTextBox to the TextFocus RibbonTab. The second TextBox has the Text to be selected when it receives focus.



public partial class MainWindow : RibbonWindow
    public MainWindow()
    private void Text2_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
        if (Text2 != null && !string.IsNullOrEmpty(Text2.Text))
    private void Text2_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
              e.Handled = true;

The following screenshot displays the RibbonTextBox with focus.

Handle the focus in WPF Ribbon control

View sample in GitHub.

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon