How to remove selected item WPF

Nov 17, 2012 at 11:14 AM
Edited Nov 17, 2012 at 12:27 PM

Hi, How to remove selected item of ListBox in MyViewModel.

How to access ListBox SelectedItems & SelectedIndex for remove selected item.




Nov 18, 2012 at 5:30 AM
Edited Nov 18, 2012 at 5:32 AM

SelectedItems consider a behavior... There are plenty of examples of this.


for selecteditem, bind to an property in the viewmodel of the type associated with the selected item, mode = twoway

--XAML --
<ListBox   SelectedItem="{Binding SomeItemProp, Mode=TwoWay}" />

-- C# --

public int SomeItemProp {
   get{ return _someItemProp;}
          _someItemProp = value;

remove it from the collection that is bound to the ListBox and refresh or update

Nov 18, 2012 at 7:49 AM

Thanks so much.