I've tried to search for this for quite some time and haven't found results that help. (perhaps my google-foo needs work?) I'm also fairly new to WPF MVVM, so there is a lot I'm still learning.
My Question is actually in two parts... Firstly, I have a Combobox that has Checkboxes within them within a View. Code:
<ComboBox Grid.Column="0"
Grid.ColumnSpan="5"
Margin="15,0,0,0"
ItemsSource="{Binding StaffNames}"
SelectedValue="{Binding SelectedStaffNames}"
Grid.Row="4">
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Path=FullName}"
VerticalAlignment="Center"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ComboBoxItem}}, Path=IsSelected,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window},
Path=DataContext.CheckBoxSelected}"
Margin="3">
</CheckBox>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Everytime I check a checkbox, it seems that the checkboxes get automatically unchecked.
My ViewModel code is as follows.
private bool _isSelected;
public bool IsSelected
{
get
{
return _isSelected;
}
set
{
_isSelected = value;
RaisePropertyChanged("IsSelected");
}
}
What is wrong here?
My second question is: Once the above is resolved, I need to append all checked names (staff names in this case) to a list and pass the values back to a separate view/view model.
I'm at a complete loss for how to accomplish this. Any help or suggestions would be greatly appreciated.
Thanks :)