简体   繁体   中英

Listbox selecting first item again wpf mvvm not working

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.

  • 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.

您可以将selectedItem设置为null,然后将其设置回所需的值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM