This is a migrated thread and some comments may be shown as answers.
Initial Focus on RadToolbar button
3 Answers 35 Views
This is a migrated thread and some comments may be shown as answers.
Christian Burkhardt
Top achievements
Rank 1
Christian Burkhardt asked on 01 Aug 2011, 09:26 AM
Hi,

I have a toolbar with a button on it like this:

    <telerik:RadToolBar Grid.Row="1"
               OverflowButtonVisibility="Visible"
               MouseLeftButtonDown="UIElement_OnMouseLeftButtonDown">
 
 
            <telerik:RadButton x:Name="newButton"
                Command="{Binding CreateNewCommand}">
                <StackPanel Orientation="Horizontal">
                    <Image Source="../NewDocument.png"
                        Stretch="None"/>
                    <TextBlock Text="New"
                        VerticalAlignment="Center"
                        Margin="5,0,5,0"/>
                </StackPanel>
            </telerik:RadButton>
...


This xaml is part of a user control called MainPage which gets loaded in a user control called Shell, which gets loaded in App.xaml
Client asked to have keyboard shortcuts for my RadToolbar commands, like (Ctrl+Shift+S) for the save button.
I know RadToolbar doesn't support this yet, so I started coding a solution which handles key down evens in the user control "Shell":

        public Shell()
        {
            InitializeComponent();
            AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(Shell_OnKeyDown), true);
        }
 
        private void Shell_OnKeyDown(object sender, KeyEventArgs e)
        {
            if (Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift) && e.Key == Key.S)
            {
//do something
            }
        }


This works well in IE. In all the other browsers I have to first click somewhere inside shell, and only then will the keyboard shortcuts work. 
I think it has to do with the fact that no control has the focus.
All I have on the MainPage user control, when it's initially loaded is a toolbar with some buttons.
I've tried setting the focus on a RadButton from the toolbar explicitly, in the LoadedEvent of the user control, but it doesn't work.

Any thoughts on how I could accomplish this?

3 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 04 Aug 2011, 12:11 PM
Hi Christian Burkhardt,

You can try focusing the MainPage control when the Shell is loaded like so:
private void Shell_Loaded(object sender, RoutedEventArgs e)
{
    System.Windows.Browser.HtmlPage.Plugin.Focus();
    mainPageControl.Focus();
}
That should do the trick.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Christian Burkhardt
Top achievements
Rank 1
answered on 04 Aug 2011, 05:19 PM
Hey, 

Thanks for the quick reply, I tried your code, but doesn't seem to fix the problem  :( 
Have you tried this in a sample and it works for you?
0
Tina Stancheva
Telerik team
answered on 09 Aug 2011, 03:42 PM
Hi Christian Burkhardt,

Please find attached a sample project where this approach is used. It works as expected on our side. Give ti a try on yours and let us know how it goes.

Kind regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Asked by
Christian Burkhardt
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Christian Burkhardt
Top achievements
Rank 1
Share this question
or