how to Set Focus on FilterDescriptor in form load
7 Answers, 1 is accepted
The FilterDescriptor is not an UI element. How do you want to focus it? Please, elaborate.
Kind regards,
Ross
the Telerik team
I have filter with default filter descriptors. When form loads I want to focus first input control.
I have tried something like this for TextBox - input (rdFilter is RadDataFilter type):
void
FilterDescriptorsWn_Loaded(
object
sender, RoutedEventArgs e)
{
TextBox tbToFocus = Extensions.VisualHelpers.FindElementOfType(rdFilter,
typeof
(TextBox))
as
TextBox;
if
(tbToFocus !=
null
) Dispatcher.BeginInvoke((EventHandler)
delegate
{
tbToFocus.Focus();
},
new
object
[2]);
}
Please help
The focus logic is handled by the .NET Framework. When you press Tab the next UIElement in the Tab order is focused and that is the normal "by design" behavior of the Framework.
You can't expect the focus logic to skip several controls and go to the next editor directly. What about the people who want to change the Member Name from the combo, then Tab, then change the FilterOperator from the next combo, then Tab, then edit value in the editor, then Tab, then check/uncheck the MatchCase button, then Tab and go down to next line. What about them?
This is the default tabbing order and that this could not be changed.
I hope this makes sense.
Ross
the Telerik team
<
StackPanel
Name
=
"stFilterDesciptorUI"
Orientation
=
"Vertical"
Grid.Column
=
"0"
Grid.Row
=
"0"
KeyboardNavigation.TabNavigation
=
"Cycle"
>
<
StackPanel
Name
=
"stFilterDesciptorUI1"
Orientation
=
"Horizontal"
Focusable
=
"False"
>
<
Button
Focusable
=
"False"
>Add</
Button
>
<
ComboBox
Focusable
=
"False"
></
ComboBox
>
<
TextBox
Width
=
"100"
Name
=
"tbFilterDesciptorUI1"
></
TextBox
>
<
Button
Focusable
=
"False"
>Remove</
Button
>
</
StackPanel
>
<
StackPanel
Name
=
"stFilterDesciptorUI2"
Orientation
=
"Horizontal"
Focusable
=
"False"
>
<
Button
Focusable
=
"False"
>Add</
Button
>
<
ComboBox
Focusable
=
"False"
></
ComboBox
>
<
TextBox
Width
=
"100"
Name
=
"tbFilterDesciptorUI2"
></
TextBox
>
<
Button
Focusable
=
"False"
>Remove</
Button
>
</
StackPanel
>
<
StackPanel
Name
=
"stFilterDesciptorUI3"
Orientation
=
"Horizontal"
Focusable
=
"False"
>
<
Button
Focusable
=
"False"
>Add</
Button
>
<
ComboBox
Focusable
=
"False"
></
ComboBox
>
<
TextBox
Width
=
"100"
Name
=
"tbFilterDesciptorUI3"
></
TextBox
>
<
Button
Focusable
=
"False"
>Remove</
Button
>
</
StackPanel
>
</
StackPanel
>
What with other users? Simply add property called FocusMode and properies Focusable="False" will depends on selected FocusMode.
Perhaps for only my purpose it will be easier to somehow use Style and set default values for controls with are rendered by DateFilter?
What with my prevoius question. How to focus first input element: I workaround that using code:
protected
override
void
OnOpened(EventArgs args)
{
base
.OnOpened(args);
DispatcherTimer timer =
new
DispatcherTimer();
timer.Tick += (o, e) =>
{
TextBox tbToFocus = Extensions.VisualHelpers.FindElementOfType(rdFilter,
typeof
(TextBox))
as
TextBox;
if
(tbToFocus !=
null
) tbToFocus.Focus();
timer.Stop();
};
timer.Interval = TimeSpan.FromSeconds(0.1);
timer.Start();
}
Maybe there was some kind of misunderstanding here. Are we talking about RadDataFilter for WPF here?
I am not sure where this XAML comes from. We do not have anything similar in RadDataFilter for WPF. The control template for RadDataFilter is entirely different from this XAML so I am not sure what this actually is. Did you invent this XAML?
If you want to make some of the child controls not focusable, then you can edit the control template of the FilterControl component (this is the thing that contains the two combo-boxes and the editor) and mark them with IsTabStop=false. We can not make a new property called FocusMode since this does not make a lot of sense. If it did, then all other WPF controls in the world would have such property and that would be built-in the .NET Framework to begin with. So I am afraid that we cannot add this new property.
As for your other question, I am afraid that there isn't a more elegant way to focus the first editor form the one that you have already discovered.
Kind regards,
the Telerik team
I have done something like this:
<
telerik:RadDataFilter
Grid.Row
=
"1"
Name
=
"rdFilter"
>
<
telerik:RadDataFilter.Style
>
<
Style
>
<
Style.Resources
>
<
Style
TargetType
=
"{x:Type telerik:RadButton}"
>
<
Setter
Property
=
"Focusable"
Value
=
"False"
></
Setter
>
</
Style
>
<
Style
TargetType
=
"{x:Type telerik:RadComboBox}"
>
<
Setter
Property
=
"Focusable"
Value
=
"False"
></
Setter
>
</
Style
>
<
Style
TargetType
=
"{x:Type telerik:RadToggleButton}"
>
<
Setter
Property
=
"Focusable"
Value
=
"False"
></
Setter
>
</
Style
>
<
Style
TargetType
=
"{x:Type df:FilterEditor}"
>
<
Setter
Property
=
"Focusable"
Value
=
"False"
></
Setter
>
</
Style
>
</
Style.Resources
>
</
Style
>
</
telerik:RadDataFilter.Style
>
</
telerik:RadDataFilter
>
Please help.