10 Answers, 1 is accepted
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
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();
}
}
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
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}}"
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
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.
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
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.
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();
}
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