This is a migrated thread and some comments may be shown as answers.

Focus AutocompleteBox

10 Answers 355 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
band
Top achievements
Rank 1
band asked on 27 Oct 2016, 02:20 PM
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?

10 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 28 Oct 2016, 08:45 AM
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!
0
band
Top achievements
Rank 1
answered on 31 Oct 2016, 07:21 PM

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();
    }
         
}

 

 

0
Nasko
Telerik team
answered on 02 Nov 2016, 08:56 AM
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!
0
band
Top achievements
Rank 1
answered on 02 Nov 2016, 06:42 PM

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}}"

       

0
Nasko
Telerik team
answered on 04 Nov 2016, 08:23 AM
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!
0
band
Top achievements
Rank 1
answered on 06 Jan 2017, 04:54 PM

Hi,

I tried to attach the file but the attachment options only allow the following extensions : jpg, jpeg, gif and png.

So I've uploaded the file here http://www.filedropper.com/telerikdemo 

 

I've create a sample solution to illustrate my issue.

Look forward to hearing back from you. 

0
Nasko
Telerik team
answered on 09 Jan 2017, 09:39 AM
Hello,

We have modified the provided sample with the described in my previous response approach - notice that now the focus is restored to RadAutoCompleteBox when the BusyIndicator hides.

Hope this helps.

Regards,
Nasko
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
band
Top achievements
Rank 1
answered on 09 Jan 2017, 04:01 PM
Hi Nasko,

Thank you taking the time to help with this situation. It solution you provided works really well, the only thing I was wondering is how to not set the focus to the autocomplete box upon loading the view. It should only trigger the focus on click. 
0
band
Top achievements
Rank 1
answered on 09 Jan 2017, 04:15 PM
Sorry I should specify alittle more what I mean.

In my main project I have the busy indicator running to load the view. So since that runs on initial load, it automatically focus the autocomplete box.

public HomeViewModel(IEventAggregator events)
{
    Events = events;
    BusyTrigger();
}

0
Accepted
Nasko
Telerik team
answered on 10 Jan 2017, 08:13 AM
Hi,

You could achieve the desired by handling the PreviewMouseLeftButtonDown event of the AutoCompleteBox. Using a bool property you could indicate if the event has been triggered and only it it has been to call the Focus method - thus it will be focused only on click.

The project has been modified with the described approach.

Hope this helps.

Regards,
Nasko
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
AutoCompleteBox
Asked by
band
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
band
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or