First, you don't implement OnChanged event in your model, only the view model.
Next, one thing you have to be careful with in databinding is the "new" keyword.
The practice that I have found to work the best for me is declare the variable
privateObservableCollection<SharedModel> _List;
public ObservableCollection<SharedModel> List
{
get { return _List; }
set { _List = value; OnPropertyChanged("List");}
}
Then I initialize it in the constructor so that it is only using the "new" keyword one time. The reason for this is that the "new" keyword will often "break" the binding. I am not sure if you want to modify the list from the viewmodel, so I usually specify Two-Way for the mode so that I can change items from both the view and viewmodel. I also change the update source trigger, but IIRC lostfocus is the default.
<Listview Itemssource="{Binding List, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
Then in your item template, your IsSelected should update.
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"
MinWidth="170" MaxWidth="170"
Margin="0,0, 0, 0" >
<CheckBox x:Name="TestCheckbox"
Tag="{Binding Method}" IsChecked="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<ContentPresenter
Content="{Binding Name}"
Margin="5,0, 15, 0" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
I don't know if you use a command, or event or whatever you do to get to GetSelectedCheckboxes(), but there are a million different ways to return all of the true selections. one way might be:
public string GetSelectedCheckboxes()
{
List<string> yourlist = List.where(l => l.IsSelected == true).Select(x => x.Method).ToList();
return yourlist;
}
Hope this helps, if you need me to clarify further I will just let me know.
Edit: To show you how I set it up.
public class SharedModel
{
public bool IsSelected { get; set; }
public string Name { get; set; }
public string Method { get; set; }
}
public class TestViewModel : ObservableObject
{
privateObservableCollection<SharedModel> _List;
public ObservableCollection<SharedModel> List
{
get { return _List; }
set { _List = value; OnPropertyChanged("List");}
}
public TestViewModel()
{
List = new ObservableCollection<SharedModel>()
{
new SharedModel()
{
Name = "A1",
IsSelected = false
},
new SharedModel()
{
Name = "A2",
IsSelected = false
}
};
}
public List<string> GetSelectedCheckboxes()
{
List<string> selectedCheckboxes = List.Where(x => x.IsSelected == true).Select(x => x.Name).ToList();
return selectedCheckboxes;
}
This along with you setting the DataContext should work. All you have to do is wire up a button to call GetSelectedCheckboxes() and that list will be only checkboxes that are selected.