How to bind multiple selection of listview to viewmodel?

后端 未结 9 2114
刺人心
刺人心 2020-12-13 09:14

I am implementing a listview, and a button next to it. I have to be able that when i select multiple items in a listview, and then click on a button, then the selected items

9条回答
  •  失恋的感觉
    2020-12-13 09:48

    I did a solution for this, to me this was simple enough.

    
                                
                                    
                                        
                                        
                                    
                                
                            
    

    Then in the viewmodel:

    public ICommand ExecuteListBoxSelectionChange { get; private set; }
    ExecuteListBoxSelectionChange = DelegatingCommand.For(ListBoxSelectionChnageEvent).AlwaysEnabled();
    

    SelectedModels is the list where I wanted the selection to be filled.

        private void ListBoxSelectionChnageEvent(ListBox modelListBox)
        {
            List tempModelInfo = new List();
             foreach(ModelInfo a in modelListBox.SelectedItems)
                 tempModelInfo.Add(a);
    
             SelectedModels = tempModelInfo;
        }
    

提交回复
热议问题