Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > ToolBar > Initial Focus on RadToolbar button

Not answered Initial Focus on RadToolbar button

Feed from this thread
  • Christian Burkhardt avatar

    Posted on Aug 1, 2011 (permalink)

    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?

    Reply

  • Tina Stancheva Tina Stancheva admin's avatar

    Posted on Aug 4, 2011 (permalink)

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

    Reply

  • Christian Burkhardt avatar

    Posted on Aug 4, 2011 (permalink)

    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?

    Reply

  • Tina Stancheva Tina Stancheva admin's avatar

    Posted on Aug 9, 2011 (permalink)

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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > ToolBar > Initial Focus on RadToolbar button
Related resources for "Initial Focus on RadToolbar button"

Silverlight ToolBar Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]