4 Answers, 1 is accepted
0
Hello David,
Calling the Focus method of the RadComboBox results in the cursor appearing if there is no SelectedItem set. Otherwise, the text within it will be selected and typing will override the value. Isn't this the behavior you are looking for? Please have a look at the sample. Do you see a different behavior in your setup? Please share more information on your scenario.
Regards,
Stefan Nenchev
Telerik by Progress
Calling the Focus method of the RadComboBox results in the cursor appearing if there is no SelectedItem set. Otherwise, the text within it will be selected and typing will override the value. Isn't this the behavior you are looking for? Please have a look at the sample. Do you see a different behavior in your setup? Please share more information on your scenario.
Regards,
Stefan Nenchev
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
David
Top achievements
Rank 1
answered on 03 Mar 2017, 04:20 PM
Hi Stefan,
Thanks for the reply. You are right. That is the behavior I'm looking for, however I am acquiring it through an Attached Property so I can control Focus through a View Model.
When I set the Attached Property "IsFocused" to "True", the TextBox portion of the ComboBox does not focus.
Here is the Attached Property for your reference.
public
class
RadComboBoxProperties
{
public
static
DependencyProperty IsFocusedProperty = DependencyProperty.RegisterAttached(
"IsFocused"
,
typeof
(
bool
),
typeof
( RadComboBoxProperties ),
new
UIPropertyMetadata(
false
, OnIsFocusedChanged ) );
public
static
bool
GetIsFocused( DependencyObject dependencyObject )
{
return
(
bool
)dependencyObject.GetValue( IsFocusedProperty );
}
public
static
void
SetIsFocused( DependencyObject dependencyObject,
bool
value )
{
dependencyObject.SetValue( IsFocusedProperty, value );
}
public
static
void
OnIsFocusedChanged( DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
{
RadComboBox comboBox = dependencyObject
as
RadComboBox;
bool
newValue = (
bool
)dependencyPropertyChangedEventArgs.NewValue;
bool
oldValue = (
bool
)dependencyPropertyChangedEventArgs.OldValue;
if
( newValue && !oldValue && !comboBox.IsFocused )
{
comboBox.Focus();
}
}
}
0
Accepted
Hello David,
The reason the focus is not set to the RadComboBox properly is because when the Focus method is invoked, the control has not yet been fully loaded.
You will need to use a Dispatcher for this to work. Here's an interesting thread discussing a similar issue.
Therefore, you can define the OnIsFocusedChanged method like so:
Do let me know if this works for you.
Regards,
Dilyan Traykov
Telerik by Progress
The reason the focus is not set to the RadComboBox properly is because when the Focus method is invoked, the control has not yet been fully loaded.
You will need to use a Dispatcher for this to work. Here's an interesting thread discussing a similar issue.
Therefore, you can define the OnIsFocusedChanged method like so:
public
static
void
OnIsFocusedChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
RadComboBox comboBox = dependencyObject
as
RadComboBox;
bool
newValue = (
bool
)dependencyPropertyChangedEventArgs.NewValue;
bool
oldValue = (
bool
)dependencyPropertyChangedEventArgs.OldValue;
if
(newValue && !oldValue && !comboBox.IsFocused)
{
comboBox.Dispatcher.BeginInvoke((Action)(() =>
{
comboBox.Focus();
}), DispatcherPriority.Render);
}
}
Do let me know if this works for you.
Regards,
Dilyan Traykov
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
David
Top achievements
Rank 1
answered on 13 Mar 2017, 04:00 AM
Works like a charm. Thanks!