Why does my TextBox get focused when clicking inside of ScrollViewer?

windows, windows-runtime, xaml

Solution

Found a solution! Setting the ScrollViewer's `TabStop="true"` prevents this behavior.

Problem

In my Windows Store app, I've created a ScrollViewer (with a Grid inside) with a few TextBoxes inside. Whenever the user clicks anywhere within the ScrollViewer, the first TextBox is focused. I have no idea why this happens, and it certainly is not the behavior I want. Is this just a symptom of XAML trying to be "helpful"? How do I prevent it? Edit: I found a clue. This only occurs when my TextBoxes are inside of a ScrollViewer. It also occurs on both C++ and C# projects, so it's obviously a symptom of XAML/WinRT. Adding example XAML: With the following XAML, if I focus the second TextBox and then click anywhere in the margin between the boxes, the first TextBox is automatically focused. I don't want it to be focused. ``` <ScrollViewer Background="#111111" VerticalScrollBarVisibility="Auto"> <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <TextBox Grid.Row="0" /> <TextBox Grid.Row="1" /> </Grid> </ScrollViewer> ```

Original source