Initial Focus on RadToolbar button

4 posts, 0 answers
  1. Christian Burkhardt
    Christian Burkhardt avatar
    23 posts
    Member since:
    Feb 2010

    Posted 01 Aug 2011 Link to this post

    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?

  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 04 Aug 2011 Link to this post

    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 >>

  3. DevCraft banner
  4. Christian Burkhardt
    Christian Burkhardt avatar
    23 posts
    Member since:
    Feb 2010

    Posted 04 Aug 2011 Link to this post

    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?
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 09 Aug 2011 Link to this post

    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 >>

Back to Top