The code has detected the SelectedItem is not null, and I think it's better to detect container is not null too. Especially when the ComboBox dropdown is never open.
If the given target of the Keyboard.Focus method is null, the keyboard will focus to the RootVisual like MainWindow. It causes the keyboard focus changes if the keyboard has been already focused on it. But in .NET WPF code, when the IsKeyboardFocusWithin changed, it may cause the dropdown closed immediately.
The code has detected the SelectedItem is not null, and I think it's better to detect container is not null too. Especially when the ComboBox dropdown is never open.
If the given target of the
Keyboard.Focus
method is null, the keyboard will focus to the RootVisual like MainWindow. It causes the keyboard focus changes if the keyboard has been already focused on it. But in .NET WPF code, when the IsKeyboardFocusWithin changed, it may cause the dropdown closed immediately.