Hi,@fatih uyanık. Welcome Microsoft Q&A.
By default, WPF controls like ListView do not receive focus when they are empty. This behavior is intentional and helps improve the user experience by avoiding confusion and ensuring that the user only interacts with controls that are currently usable.
You could use the following code to override this behavior and allow the ListView to receive focus when it is empty.
<Window ...
PreviewKeyDown="ListView_PreviewKeyDown"
>
<StackPanel>
<TextBox Text="hello" Height="100" Width="100" Background="Aquamarine"/>
<ListView Name="lv" Focusable="True" Height="100" >
<ListView.Style>
<Style TargetType="ListView">
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</ListView.Style>
</ListView>
</StackPanel>
</Window>
codebedhind:
private void ListView_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Tab)
{
lv.Focus();
e.Handled = true;
}
}
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.