microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

`TextBox` inside a `ScrollViewer` does not lose focus when click in empty spaces

Open HO-COOH opened this issue 1 year ago • 2 comments

Describe the bug

TextBox inside a ScrollViewer does not lose focus when click in empty spaces, but a TextBox inside any other panel does.

Steps to reproduce the bug

  1. Use this xaml
 <Grid Margin="50">
     <Grid.ColumnDefinitions>
         <ColumnDefinition Width="*" />
         <ColumnDefinition Width="*" />
     </Grid.ColumnDefinitions>

     <ScrollViewer Background="Red">
         <TextBox
             Width="500"
             VerticalAlignment="Center"
             PlaceholderText="This TextBox inside ScrollViewer does not lose focus when click in the red area" />
     </ScrollViewer>


     <Grid Grid.Column="1" Background="Blue">
         <TextBox
             Width="500"
             VerticalAlignment="Center"
             PlaceholderText="This TextBox inside Grid lose focus when click in the blue area" />
     </Grid>
 </Grid>

Expected behavior

No response

Screenshots

Image

NuGet package version

Image

Windows version

No response

Additional context

Related #3825 Repro

HO-COOH avatar Oct 10 '24 17:10 HO-COOH

@codendone This is really an inconvenient issue :-|

MartyIX avatar Jun 12 '25 17:06 MartyIX

I suspect the problem is the fix for #597 (internal bug), which added this code. Marking the PointerReleased as handled is probably preventing the unfocusing (which I think may be moving focus to the root visual).

Setting IsTabStop="true" on the ScrollViewer will allow the ScrollViewer to instead take focus in this situation, which may or may not be an improvement.

codendone avatar Jun 12 '25 18:06 codendone