WPF MVVM disables focus on ContentControl (using Tab key)
I have a window with an anchor ContentControl
:
<ContentControl Content="{Binding CurrentViewModel}" />
I also have an empty custom control associated with 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 key, I get a dotted rectangle around the content control. How can I disable this?
I have tried using Focusable="False"
and FocusVisualStyle="{x:Null}"
without success ...
+3
source to share
2 answers
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 answer to this question: WPF and initial focus
0
source to share