0

考虑 WPF (MVVM) 中的一个列表框,其中包含一个项目列表(项目是文件名)。如果选择了列表框中的第一个项目,则第一个文件将被正确打开。假设,如果单击“新建”按钮(打开新文件)并打开新文件。现在,如果第一个项目(第一个文件)被选中,那么第一个文件没有打开 insetead new 只会打开,因为列表框选择没有改变。相反,如果选择了任何其他项目,那么它工作正常。如何使第一个项目再次被选中。

4

2 回答 2

1

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

于 2012-10-09T19:41:05.023 回答
0
  • 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.
于 2012-10-09T17:09:43.187 回答