Reputation: 5794
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>
Upvotes: 6
Views: 1512
Reputation: 5794
Found a solution! Setting the ScrollViewer's TabStop="true"
prevents this behavior.
Upvotes: 10