Focus AutocompleteBox

6 posts, 0 answers
  1. band
    band avatar
    12 posts
    Member since:
    Jun 2016

    Posted 27 Oct Link to this post

    Hi, when entering the view, I would like the user to be instantly able to type away at the autocompletebox upon view loaded. I tried Autocompletebox.Focus event but that doesn't quite focus. May I ask how abouts do I focus Autocompletebox?
  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 28 Oct Link to this post

    Hello band,

    In order to achieve the desired behavior you can handle the view's Loaded event, get ahold of the RadAutoCompleteBox by its Name property or using the ChildrenOfType extension method.

    public MainWindow()
    {
        InitializeComponent();
        this.Loaded += MainWindow_Loaded;
    }
     
    private void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        //this.ChildrenOfType<RadAutoCompleteBox>().First().Focus();
        this.autoCompleteBox.Focus();
    }

    Both of the aforementioned approaches work correctly at my end. Could you please let me know if they work for you as well? If that is not the case, please provide more information regarding your exact setup and I will happily assist you further.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
  3. UI for WPF is Visual Studio 2017 Ready
  4. band
    band avatar
    12 posts
    Member since:
    Jun 2016

    Posted 31 Oct Link to this post

    Hi Dilyan,

    This conflicts with some current code i have at the moment.

    I have a GotFocus event, when the autocompletebox is clicked, it populates autocopletebox's itemsSource.

    I have a RadBusyIndicator that appears while itemsSource is populating, the autocompleteBox loses it's focus when radbusyindicator appears. I've put an await and tried to set the focus again but still no luck.

    private bool doubleFocus = false;
    private async void AutoCompleteBox_OnGotFocus(object sender, RoutedEventArgs e)
    {
        if (!doubleFocus)
        {
            var dataContext = (GeneralInquiryViewModel) DataContext;
            await dataContext.InitializeCollectionAsync();
            doubleFocus = true;
            this.autoCompleteBox.Focus();
        }
             
    }

     

     

  5. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 02 Nov Link to this post

    Hi,

    Please, check the following article from our help documentation that provides detailed information how to restore the focus to the desired control after RadBusyIndicator hides:
    http://docs.telerik.com/devtools/wpf/controls/radbusyindicator/how-to/restore-the-focus

    Hope this will help you.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
  6. band
    band avatar
    12 posts
    Member since:
    Jun 2016

    Posted 02 Nov in reply to Nasko Link to this post

    Hi, 

    I can't seem to use the first method because it points to element radBusiIndicator but the two objects don't reside on the same user control.

    <telerik:RadBusyIndicator x:Name="RadBusyIndicator"
                              IsBusy="{Binding ShellBusy}"
                              BusyContentTemplate="{StaticResource ProgressSpinner}" 
                              Background="Transparent"
                              BorderBrush="Transparent" KeyboardNavigation.IsTabStop="False" >
        <telerik:RadBusyIndicator.ProgressBarStyle>
            <Style TargetType="telerik:RadProgressBar">
                <Setter Property="Visibility" Value="Collapsed"/>
            </Style>
        </telerik:RadBusyIndicator.ProgressBarStyle>
        <ContentControl x:Name="ActiveItem"
                        HorizontalContentAlignment="Stretch"
                        VerticalContentAlignment="Stretch"                       
                        KeyboardNavigation.IsTabStop="False" />
    </telerik:RadBusyIndicator>

     

     

    So what I tried to do instead was point it to the ancestor  but it produces an error upon loading. Any help would be greatly appreciated. 

     

    <Telerik:RadAutoCompleteBox
                          Framework:FocusHelper.EnsureFocus="{Binding IsBusyIndicationVisible, RelativeSource={RelativeSource FindAncestor, AncestorType=Telerik:RadBusyIndicator}}"

           

  7. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 04 Nov Link to this post

    Hello,

    Could you please provide us a sample project that demonstrates your exact scenario? From the provided code-snippet we are not exactly sure how exactly the BusyIndicator and the AutoCompleteBox are arranged in your XAML. Using the sample we will be able to observe your exact scenario on our side and we will try to provide you with a prompt solution.

    We are looking forward to hearing from you.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
Back to Top
UI for WPF is Visual Studio 2017 Ready