I have WPF ComboBox containing CheckBox items, and it allows the user to select multiple items.
I want to display the list of selected items as comma seperated text on the combobox after the user has selected an item from the combobox.
XAML:
<ComboBox Name="cmbEnvironment" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding IsSelected}" Content="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Code Behind:
var lstEnvironment = new List<Environment>();
lstEnvironment.Add( new Environment() { Name = "Env1", IsSelected = false});
lstEnvironment.Add(new Environment() { Name = "Env2", IsSelected = false });
lstEnvironment.Add(new Environment() { Name = "Env3", IsSelected = false });
cmbEnvironment.ItemsSource = lstEnvironment;
Model:
public class Environment
{
public string Name { get; set; }
public bool IsSelected { get; set; }
}
How can I accomplish this?