3

I have a window with a ContentControl binding:

<ContentControl Content="{Binding CurrentViewModel}" />

I also have an empty user control binds to the ContentControl:

<UserControl x:Class="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" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
    </Grid>
</UserControl>

When I run and press the tab keyboard I get a dotted rectangle around the content control. How can I disable this?

I tried using Focusable="False" and FocusVisualStyle="{x:Null}" without success...

MarthyM
  • 1,839
  • 2
  • 21
  • 23
Dikla
  • 88
  • 8
  • Is the user control used somewhere? This seems irrelevant. When using Focusable="False" in the ContentControl it won't take the dotted rectangle. You might need to show more of your code to clear it up. – James Harcourt Jun 07 '15 at 10:37

2 Answers2

1

Have you tried setting IsTabStop="False", for example...

<ContentControl Height="200" Width="200" IsTabStop="False">
    <ContentControl.Content>
        <TextBox/>
    </ContentControl.Content>
</ContentControl>

and I would suggest you combine it with this trick:

Loaded += (sender, e) =>
MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));

from the answer to this question: WPF and initial focus

Community
  • 1
  • 1
Richardissimo
  • 5,596
  • 2
  • 18
  • 36
  • Setting IsTabStop=False on the ContentControl works great to prevent it from getting focus from Tab keys. Thanks! – Zarat Jul 24 '19 at 14:38
0

Override the ContentControl Style and add property FocusVisualStyle as null and implement by using style property

<ContentControl Height="200" Width="200" FocusVisualStyle="{x:Null}">
            <ContentControl.Content>
                <local:UserControl1/>
            </ContentControl.Content>
       </ContentControl>
ReeganLourduraj
  • 863
  • 6
  • 9