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

assigning a keyboard shortcut to a rad expander

5 Answers 189 Views
Expander
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 24 Dec 2009, 05:54 PM

Is there a way to  assign a keyboard shortcut to the rad expander so that when pressed, the rad expander will gain focus?

I am referring to both logical and keyboard focus.

For example, if I have 5 rad expanders on my form, and I am at the bottom of the form, I want to press alt+a on the keyboard to jump to the top of the form and bring focus to the address rad expander rather than having to tab several times to get back to the address rad expander.
 
I have the rad expanders in a child wpf user control which is within a window.
I have tried this syntax and it does not work:
FocusManager.SetFocusedElement(stpApplicantInformation, rxpAddressInformation)
 
In my xaml I have this:
Note: I have left out much of the xaml code but the stack panel contains 5 rad expanders and a submit button at the bottom.
<UserControl x:Class="AddressInformation"
...
<StackPanel Grid.Row="1"
                        Margin="0,0,0,0"
                        Name="stpApplicantInformation"
...
VerticalAlignment="Top" Focusable="True" 
                                     KeyboardNavigation.TabNavigation="Cycle" FocusManager.IsFocusScope="True"  Visibility="Visible">
...
<StackPanel.CommandBindings>
                    <CommandBinding Command="Help"
       CanExecute="JumpToAddress">
                    </CommandBinding>
                </StackPanel.CommandBindings>
                <StackPanel.InputBindings>
                    <KeyBinding Command="Help" Key="a" Modifiers="Alt"/>
                </StackPanel.InputBindings>
...
<!-- this rad expander I want to pressd alt+a and move keyboard and logical focus to it -->
<telerik:RadExpander Header="_Address Information"
                                     Name="rxpAddressInformation"
                                     Width="1000"
                                     Margin="0, 0, 0, 0"
                                     AllowDrop="False"
                                     Height="auto"
                                      TabIndex="1" Focusable="True" Visibility="Visible" >
                    <UserControl:Address x:Name="AddressInfo" Width="Auto" Height="Auto"></UserControl:Address>
                </telerik:RadExpander>
...
...
<Button X:Name="btnSubmit" ... />              
</StackPanel>
</UserControl>
What am I doing wrong here?
The JumpToAddress method is fired and is working but using FocusManager.SetFocusedElement(stpApplicantInformation, rxpAddressInformation) does not seem
to move keyboard focus to the address rad expander.
Help!
 
If I am on the submit button, and press alt+a I want to jump to the address rad expander.
Bill
    

5 Answers, 1 is accepted

Sort by
0
Bill
Top achievements
Rank 1
answered on 27 Dec 2009, 09:54 AM
I haven't heard back yet from anyone. Are you guys around during holiday?

Bill    
0
Bill
Top achievements
Rank 1
answered on 29 Dec 2009, 09:00 AM

Hey guys,

can you please provide me a source code example showing me how I can accomplish this keyboard task that I am attempting to program using your
rad expander? A source code example / project would be appreciated. I.E a .sln and project file showing me how to wire this up to get it to work.

Thanks!
 
Bill

    
0
Ivan
Telerik team
answered on 30 Dec 2009, 01:50 PM
Hi Bill,

First of all, we deeply apologize for the late reply.

Unfortunately the common way to bind the click event with a shortcut does not work here. However we can workaround the case easily - just put a hidden button and wire its shortcut behavior with the expander. This approach is implemented in the attached example. Please give it a try and let us know if you have other questions.


Greetings,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Bill
Top achievements
Rank 1
answered on 30 Dec 2009, 04:17 PM

Hi Ivan,

 

Thank you for the response.

 

In the sample project, on window1, can you add 4 rad expanders and a visible submit button. Like this:

 

        <telerik:RadExpander

            Name="RE1"

...

 

        <telerik:RadExpander

            Name="RE2"

...

 

        <telerik:RadExpander

            Name="RE3"

...'

 

        <telerik:RadExpander

            Name="RE4"

...

 

        <Button

            x:Name="btnSubmit">Submit</button>

 

 

Run the project. Tab down to the submit button. While on the submit button, press alt+1. When I press alt+1 it should move keyboard focus to re1. It doesn't need to expand or collapse it, just move keyboard focus to it. When I press alt+2 it should move keyboard focus to re2.  When I press alt+3 it should move keyboard focus to re3. Finally, when I press altt+4 it should move keyboard focus to re4. No matter where I am on the form, when I press alt+1, alt+2, alt+3, or alt+4 it should immediately move keyboard focus to the associated rad expander.

 

The attached project you provided is illustrating how to collapse and expand the rad expander using the keyboard, but I am trying to accomplish moving keyboard focus to the rad expanders, not collapsing and expanding them.

 

Can you please revise the project to illustrate how I can accomplish this task using the keyboard shortcuts to move keyboard focus among the 4 rad expanders?

 

Thank you.

 

Bill

0
Accepted
Ivan
Telerik team
answered on 04 Jan 2010, 02:22 PM
Hi Bill,

Focusing the expander is not so trivial task with its current implementation. What I mean is related to the focusing the expander control not its content. The easiest way to focus an expander with  a hot key is to target it with a Label control (please preview the RE4 in the attached example). Unfortunately this way you will not focus the expander's header element but the whole expander instead. As a result you should tab once more to get over the header. In order to avoid this issue we workaround again with an invisible button (as it is done for all other expanders - RE1, RE2, RE3). The trick is to find the header element and to focus exactly it.

Please preview the attached example and let us know if there are more questions.

Regards,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Expander
Asked by
Bill
Top achievements
Rank 1
Answers by
Bill
Top achievements
Rank 1
Ivan
Telerik team
Share this question
or