0

I'm having a weird problem. I binded some keyboard shortcuts like so:

BroadcastView XAML:

<UserControl.InputBindings>
  <KeyBinding Key="F1" Command="{Binding StartRoundClockCmd}"/>
  <KeyBinding Key="F2" Command="{Binding StopRoundClockCmd}"/>
</UserControl.InputBindings>

MainWindow XAML

<Grid>
    <TabControl>
        <TabItem Header="Broadcast">
            <view:BroadcastView/>
        </TabItem>
        <TabItem Header="Options">
            <view:OptionsView/>
        </TabItem>
    </TabControl>
</Grid>

but the problem is.. when I start the application.. F1 and F2 don't work.. i can click anywhere within the TabItem thinking I just need it to focus the tabitem.. but still nothing.. it's only when I click within a textbox.. or click a button on the View (within the TabItem) first.. THEN the keyboard shortcuts work.

how can I get it so that the keyboard shortcuts will work from application startup using MVVM?

user1189352
  • 3,628
  • 12
  • 50
  • 90

1 Answers1

1

I would use Keyboard.Focus and FocusManager if I were you. You can set the focus on your usercontrol so it receives the keyboard shortcuts.

Huhra
  • 92
  • 4