Working with the TouchScreen application, which also has a keyboard, I have the following problem:
The WPF window has a TextBox, which should receive ALL keyboard input. There are also buttons and ListBox that are exclusively used by TouchScreen (= Mouse).
A very simple example looks like this:
<Window x:Class="KeyboardFocusTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1">
<StackPanel>
<TextBox Text="{Binding Input, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
PreviewLostKeyboardFocus="TextBox_PreviewLostKeyboardFocus"/>
<Button Click="Button_Click">Add</Button>
<ListBox ItemsSource="{Binding Strings}" />
</StackPanel>
</Window>
To keep the TextBox always focused, I just do:
private void TextBox_PreviewLostKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e)
{
e.Handled = true;
}
So far so good - the problem is that I can no longer select items from the list. This seems to work if the ListBox has keyboard focus. But if I lose the focus of the keyboard on the TextBox, I can no longer enter text without first pressing.
Any ideas, suggestions, comments are welcome!