I am trying to work towith the MVVM principles within a small WPF project using c#C#. I have a List boxListBox that is populated with CheckboxesCheckBoxes created through binding back to the ViewModel. I also have a command bound to the checkboxesCheckBoxes and wish to pass the checkbox ContentCheckBoxes Content as a commandParameterCommandParameter. I was looking atfor something like the belowthis:
UnfortuetlyUnfortunately, because the CheckboxesCheckBoxes are created through a binding I don’t have the element name.
The code for ListBoxListBox / ListBoxItem StyleListBoxItem Style is belowthis:
<Style x:Key="CheckBoxListStyle" TargetType="{x:Type ListBox}"> <Setter Property="SelectionMode" Value="Multiple"></Setter> <Setter Property="ItemContainerStyle"> <Setter.Value> <Style TargetType="{x:Type ListBoxItem}" > <Setter Property="Margin" Value="2" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBoxItem}"> <CheckBox Command="{Binding SelectedItemCommand, Mode=OneWay, Source={StaticResource comd}}"> <CheckBox.CommandParameter> <MultiBinding Converter="{StaticResource cv}"> <Binding ElementName="" Path="Content"/> <Binding ElementName="" Path="IsChecked"/> </MultiBinding> </CheckBox.CommandParameter> <ContentPresenter></ContentPresenter> </CheckBox> </ControlTemplate> </Setter.Value> </Setter> </Style> </Setter.Value> </Setter> </Style> And its implementation is:
Ultimately my aimgoal is to be able to display all the selected items Text Contenttext Contents (Countries in this case) inof all the selected items in a text box were each country is separated by a comma. The only thing I am currently missing is the Country. I would be grateful for any assistanceCountry.