
Hello,
The TreeListBox control will try to select an ancestor item if the current selected item is removed. However in this case you turned off IsRootItemVisible. If the root item was visible, deleting one of the child nodes would move selection up to the root item and focus would remain within the control, on that parent item's TreeListBoxItem.
Without the root item visible, the code as you have it will effectively remove the selected item's TreeListBoxItem, which is currently focused. When a focused WPF control is removed from the visual tree in general, WPF moves focus to the Window. I think that's what's going on here.
A better way to do things is to update your view model to two-way bind to the TreeListBox.SelectedItem and make an appropriate SelectedItem change to an item not being removed, prior to removing an item.
If you do that, and also change your "x" Button to be Focusable="False", it will keep focus within the control as long as you have selected another remaining item. The Focusable="False" is needed since the Button might be moving focus elsewhere after click.
Now the problem that remains is when there are no other remaining items to select, such as when you are removing the last item. We will update our logic for the next build to focus the TreeListBox control itself when no selection remains after an item is removed. That will handle this last case, and also if you didn't update the SelectedItem as suggested above.