Patrice said:
So the item you set in the button click doesn't exists (not sure where the
button takes the item to select) ? Then you would have -1 to indicate that
nothing is selected...
We don't need the whole code. You need to create the simplest "proof of
concept" that shows this problem. Or quickly built a simple app that just
define the selected item from a button click, each item being whatever
dummy data that may fit.
During this simplification process you'll likely find yourself the
cullprit. If not you have then the minimal amount of code that shows the
problem so that others can give a look at it..
This is a trace with the simplest of code: the events I did are surrounded
by **********
****************
Initial load of Listview
****************
Focus got by : Button CDButton selected index is -1
Focus got by : ListViewItem selected index is -1
Focus got by : ScrollViewer selected index is -1
Focus got by : ListView CDList selected index is -1
Focus got by : FolderList CDList selected index is -1
Focus got by : FolderNavigator theFolderNavigator selected index is -1
Focus got by : TabItem selected index is -1
Focus got by : TabControl navTabs selected index is -1
Focus got by : MainWindow selected index is -1
Focus lost by : Button CDButton selected index is -1
Focus lost by : ListViewItem selected index is -1
Focus lost by : ScrollViewer selected index is -1
Focus lost by : ListView CDList selected index is -1
Focus lost by : FolderList CDList selected index is -1
Focus lost by : FolderNavigator theFolderNavigator selected index is -1
Focus lost by : TabItem selected index is -1
Focus lost by : TabControl navTabs selected index is -1
Focus lost by : MainWindow selected index is -1
Focus got by : ListView SongView selected index is -1
SongView_GotFocus
SelectedIndexChange 0 - from the SelectedIndexChange Event
**********
Pressed DownArrow
**********
Focus lost by : ListView SongView selected index is 0
SongView_LostFocus
Focus got by : ListViewItem selected index is 0
Focus got by : ScrollViewer selected index is 0
Focus got by : ListView SongView selected index is 0
SongView_GotFocus
Key up Down selected index = 0
**********
Pressed DownArrow
**********
Focus lost by : ListViewItem selected index is 0
Focus lost by : ScrollViewer selected index is 0
Focus lost by : ListView SongView selected index is 0
SongView_LostFocus
Focus got by : ListViewItem selected index is 0
Focus got by : ScrollViewer selected index is 0
Focus got by : ListView SongView selected index is 0
SongView_GotFocus
SelectedIndexChange 1 - from the SelectedIndexChange Event
Key up Down selected index = 1
**************************
And Again pressed a DownArrow
**************************
Focus lost by : ListViewItem selected index is 1
Focus lost by : ScrollViewer selected index is 1
Focus lost by : ListView SongView selected index is 1
SongView_LostFocus
Focus got by : ListViewItem selected index is 1
Focus got by : ScrollViewer selected index is 1
Focus got by : ListView SongView selected index is 1
SongView_GotFocus
SelectedIndexChange 2 - from the SelectedIndexChange Event
Key up Down selected index = 2
********************
Pressed Keypress - Space
********************
Key up Space selected index = 2
Focus lost by : ListViewItem selected index is 2
Focus got by : ListView SongView selected index is 2
SongView_GotFocus
**********
Pressed DownArrow
**********
Focus lost by : ListView SongView selected index is 2
SongView_LostFocus
Focus got by : ListViewItem selected index is 2
Focus got by : ScrollViewer selected index is 2
Focus got by : ListView SongView selected index is 2
SongView_GotFocus
SelectedIndexChange 0 - from the SelectedIndexChange Event
###############################################
This is where it screws up. Notice that the index was 2 and that
the SongView (the listview) got focus and the selected index has changed.
Of course it the call stack for this shows only an entry for "external code"
which is where the screwup occurs. I have been trying to fix this one
thing for about 5 days. I have read so many internet entries about WPF
problems I am just about to give up on this tech as useless.
###################################################
Key up Down selected index = 0
Focus got by : Button CDButton selected index is -1
Focus got by : ListViewItem selected index is -1
Focus got by : ScrollViewer selected index is -1
Focus got by : ListView CDList selected index is -1
Focus got by : FolderList CDList selected index is -1
Focus got by : FolderNavigator theFolderNavigator selected index is -1
Focus got by : TabItem selected index is -1
Focus got by : TabControl navTabs selected index is -1
Focus got by : MainWindow selected index is -1
Focus lost by : Button CDButton selected index is -1
Focus lost by : ListViewItem selected index is -1
Focus lost by : ScrollViewer selected index is -1
Focus lost by : ListView CDList selected index is -1
Focus lost by : FolderList CDList selected index is -1
Focus lost by : FolderNavigator theFolderNavigator selected index is -1
Focus lost by : TabItem selected index is -1
Focus lost by : TabControl navTabs selected index is -1
Focus lost by : MainWindow selected index is -1
Focus got by : ListView SongView selected index is -1
SongView_GotFocus
SelectedIndexChange 0
********************
Pressed DownArrow
********************
Focus lost by : ListView SongView selected index is 0
SongView_LostFocus
Focus got by : ListViewItem selected index is 0
Focus got by : ScrollViewer selected index is 0
Focus got by : ListView SongView selected index is 0
SongView_GotFocus
Key up Down selected index = 0
*****************
Pressed DownArrow
*****************
Focus lost by : ListViewItem selected index is 0
Focus lost by : ScrollViewer selected index is 0
Focus lost by : ListView SongView selected index is 0
SongView_LostFocus
Focus got by : ListViewItem selected index is 0
Focus got by : ScrollViewer selected index is 0
Focus got by : ListView SongView selected index is 0
SongView_GotFocus
SelectedIndexChange 1
Key up Down selected index = 1
******************
And Again
******************
Focus lost by : ListViewItem selected index is 1
Focus lost by : ScrollViewer selected index is 1
Focus lost by : ListView SongView selected index is 1
SongView_LostFocus
Focus got by : ListViewItem selected index is 1
Focus got by : ScrollViewer selected index is 1
Focus got by : ListView SongView selected index is 1
SongView_GotFocus
SelectedIndexChange 2
Key up Down selected index = 2
******************
Keypress - Space
******************
Key up Space selected index = 2
Focus lost by : ListViewItem selected index is 2
Focus got by : ListView SongView selected index is 2
SongView_GotFocus
DownArrow
Focus lost by : ListView SongView selected index is 2
SongView_LostFocus
Focus got by : ListViewItem selected index is 2
Focus got by : ScrollViewer selected index is 2
Focus got by : ListView SongView selected index is 2
SongView_GotFocus
SelectedIndexChange 0
Key up Down selected index = 0