How to remove selected item WPF

Nov 17, 2012 at 10:14 AM
Edited Nov 17, 2012 at 11:27 AM

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

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

Thanks.

 

 

Nov 18, 2012 at 4:30 AM
Edited Nov 18, 2012 at 4: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;}
   set{
          _someItemProp = value;
         NotifyOfPropertyChange(()=>SomeItemProp);
   }
}

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

Nov 18, 2012 at 6:49 AM

Thanks so much.