2X faster development
The ultimate WPF UI toolkit to boost your development speed.
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. MainWindow.Xaml <syncfusion:RibbonWindow x:Class="Ribbon_131602.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:local="clr-namespace:Ribbon_131602" syncfusion:SkinStorage.VisualStyle="Metro" xmlns:syncfusion="http://schemas.syncfusion.com/wpf"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <syncfusion:Ribbon Name="MyRibbon" BackStageCornerImageVisibility="Collapsed" EnableMoreCommands="False"> <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" /> </syncfusion:RibbonBar> </syncfusion:RibbonTab> </syncfusion:Ribbon> <Grid Grid.Row="1"> <RichTextBox Margin="12"> <FlowDocument> <Paragraph> 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. </Paragraph> </FlowDocument> </RichTextBox> </Grid> </Grid> </syncfusion:RibbonWindow>
MainWindow.Xaml.cs public partial class MainWindow : RibbonWindow { public MainWindow() { InitializeComponent(); } private void Text2_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { if (Text2 != null && !string.IsNullOrEmpty(Text2.Text)) Text2.SelectAll(); } private void Text2_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if(Text2!=null) { if(!Text2.IsKeyboardFocusWithin) { e.Handled = true; Text2.Focus(); } } } } The following screenshot displays the RibbonTextBox with focus. |
2X faster development
The ultimate WPF UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.