Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable whole user control focusing from keyboard

Tags:

focus

wpf

xaml

I have UserControl in a window. When user walks window with "Tab" key user control gets focused and dashed border drawn around it. How to prevent this behavior? enter image description here

like image 438
Evil Beaver Avatar asked Dec 15 '22 07:12

Evil Beaver


1 Answers

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

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

Or set the Style to focus yourself:

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

Also, the Style of focus might 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

like image 105
Anatoliy Nikolaev Avatar answered Jan 12 '23 06:01

Anatoliy Nikolaev