Custom control does not receives the tab focus

Magesh Sankar 36 Reputation points
2020-05-11T03:32:38.52+00:00

I have custom control, which is templated like below

Blockquote

<DockPanel>
<local:CustomControl1>
<ToggleButton></ToggleButton>
</local:CustomControl1>
</DockPanel

Blockquote

Problem:

When i press tab key DockPanel can recieves the keyboard focus and but custom control failed to do so. I need to focus the control inside the Custom Control.

Please suggest any solution to resolve this.

Thanks
Maggi

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Li-MSFT 1,096 Reputation points
    2020-05-11T06:07:22.71+00:00

    Welcome to our Microsoft Q&A platform!

    You can try to add code Focusable="True" in Grid.

    <UserControl x:Class="_1.Customcontroldoesnotreceivesthe.UserControl1"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:local="clr-namespace:_1.Customcontroldoesnotreceivesthe"
                 mc:Ignorable="d" 
                 d:DesignHeight="20" d:DesignWidth="100"  >
        <Grid  Focusable="True">
    
        </Grid>
    </UserControl>
    

    Thanks.

    0 comments No comments