Disable focusing of all user controls from the keyboard

I have a UserControl in the window. When the user walks with the Tab window, the user control focuses and breaks around it. How to prevent this behavior? enter image description here

+4
source share
3 answers

That was my fault. I had xaml:

<ContentControl> <ScrollViewer name="viewport"/> </ContentControl> 

and "viewport.Content" was set to my UserControl from the code.

It was a ContentControl that drew the focus border. I deleted it and left only a. The problem is resolved.

0
source

If you just want it to not accept focus through Tabbing, just declare it on the object via IsTabStop="False" or you can edit the control template for it and get rid of Focus changes.

+5
source

Try it for the Focusable = "False" control set. Example:

 <Grid Focusable="False"> ... </Grid> 

Or configure Style for yourself:

 <Grid FocusVisualStyle="{x:Null}" /> 

In addition, the Style focus can be:

 <Style x:Key="MyItemFocusVisual" TargetType="{x:Type Control}"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Control}"> <Border SnapsToDevicePixels="True" CornerRadius="0" BorderThickness="5" BorderBrush="#7B2F81" /> </ControlTemplate> </Setter.Value> </Setter> </Style> 

Using:

 <Grid Focusable="True" FocusVisualStyle="{StaticResource MyItemFocusVisual}" ... /> 

Output

enter image description here

+3
source

Source: https://habr.com/ru/post/1495347/


All Articles