Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 869
Brent Traut Avatar asked Jan 23 '13 22:01

Brent Traut


1 Answers

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

like image 200
Brent Traut Avatar answered Oct 19 '22 09:10

Brent Traut