Why doesn't keyboard input work for a ScrollViewer when the child control has input focus?

Posted by Ashley Davis on Stack Overflow See other posts from Stack Overflow or by Ashley Davis
Published on 2010-06-10T15:58:42Z Indexed on 2010/06/10 17:02 UTC
Read the original article Hit count: 246

Filed under:
|
|

Why doesn't keyboard input work for a ScrollViewer when the child control has input focus?

This is the scenario. A WPF window opens. It sets the focus to a control that is embedded in a ScrollViewer.

I hit the up and down and left and right keys. The ScrollViewer doesn't seem to handle the key events, anyone know why?

This is the simplest possible example:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300"
    FocusManager.FocusedElement="{Binding ElementName=control}"
    >
    <Grid>
        <ScrollViewer
            HorizontalScrollBarVisibility="Auto"
           >
            <ItemsControl
                x:Name="control"
                Width="1000"
                Height="1000"
                />
        </ScrollViewer>        
    </Grid>
</Window>

When you start the app that contains this window, "control" appears to have the focus as I intended. Pressing the key seems to result in bubbling key events reaching the ScrollViewer (I checked for this using WPF Snoop). I can't work out why it doesn't respond to the input.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf