0
votes

Consider a listbox in WPF (MVVM) having a list of items(items are file names).If First item in listbox selected then the first file will be opened correctly. Suppose, if 'New' button(to open new file)is clicked and new file is opened. Now, if the first item(first file) is selected then fist file is not opening insetead new is only opened because list box selection is not changed. Instead if any other item is selected then it is working fine.How to make the first item to get selected again.

2
Sounds odd, could you provide ViewModel code ?HichemSeeSharp
add your code here...............andy
ya because it's listbox property try with single item in listbox and select that item Selectionchanged Event fire once if you try to select that item again then SelectionChanged Event doesn't execute.Dhaval Patel

2 Answers

1
votes

You can set your selectedItem to null then set it back to your value that you need.

0
votes
  • Add an extra item as "SelectFile" in databound collection of ListBox.
  • Whenenver Newbutton get clicked, through button command execution, set ListBox selected item as "SelectFile".
  • This will allow you to reselect last file.
  • If this default entry "SelectFile" get selected, do not proceed with file opening from view model.