I am currently testing C # and WPF for the first time.
I have a window with two tabs, tabA and tabB . Each tab has a list box (they are almost identical), tabA has listboxA and tabB has listboxB . When an item is selected in the list, some information about the item is displayed, so I know that it is selected.
In a specific E event, I want to highlight an item in listboxA or listboxB , which is determined by the logic in my application.
Scenario A is that I am now on tabA . When E occurs, an item in listboxA . I call listboxA.Focus() and then listboxA.SelectedItem = item . It works great. item , therefore, information about the item is displayed, and the item is highlighted in the list.
Scenario B, where I have my problem, is that I am now on tabA . When E occurs, an item in listbox B . I call tabControl.SelectedItem = tabB to switch the tab, which works fine. Like in scenario A, I call listboxB.Focus() and then listboxB.SelectedItem = item . The item is selected because information about the item is displayed, but here: item The item is not highlighted in the list .
This also happens when changing from tabB to tabA . This always happens when I change the tab, but if I stay on the same tab, the highlight works fine.
Does anyone know if there is anything else I need to do to give the focus of the list focus after changing the tab other than calling Focus() ?
source share