Right now, I'm working on a WPF project.
I have a confirmation dialog that displays a list of repeated strings that the user imported from a CSV file.
The user can check off the repeated strings they want to add to a list (listview) and click ok.
The problem is I'm not sure how to get the value of the checkbox items that are checked off and add them to a list. How do I know what checkbox is selected and add the selected items to a list?
I want to do this task using MVVM and not code behind. I've seen a few examples using code behind and they still confuse me.
I think I have to use commands but I'm not sure still how to get the selected checkbox value?
Here's my attempt:
Code in ViewModel:
private bool isSelected;
public bool IsSelected
{
get
{
return isSelected;
}
set
{
isSelected = value;
RaisePropertyChanged("IsSelected");
if (IsSelected == true)
{
foreach (var item in confirmationList.PassList)
{
List.Add(item);
}
RaisePropertyChanged(LIST);
}
else if (IsSelected == false)
{
}
}
}
XAML:
<Grid>
<ListView ItemsSource="{Binding Inventory}">
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Content="{Binding}" IsChecked="{Binding Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Name}"
Header="Name">
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Not sure what else to do from here to get the checked off values?
EDIT: updated xaml to reflect look.