question

MageshSankar-9134 avatar image
MageshSankar-9134 asked ·

Custom control does not receives the tab focus


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-wpf
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AlexLi-MSFT avatar image
AlexLi-MSFT answered ·

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.

Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.