What will be the correct way to get what are currently being checked in the CheckBox
. What i have done so far will not firing any event on CheckBox
items checked:
<ListBox Grid.RowSpan="3" Grid.Column="2" Grid.ColumnSpan="5" Margin="2" ItemsSource="{Binding MachinePositionList}">
<ListBox.ItemTemplate>
<HierarchicalDataTemplate>
<CheckBox Content="{Binding posID}" IsChecked="{Binding IsChecked, Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding CurrentCheckedPosition}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</HierarchicalDataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Thanks a lot :-).
You can use the checked events:
<CheckBox Name="myCheckBox"
Content="I am a checkbox!"
Checked="myCheckBox_Checked"
Unchecked="myCheckBox_Unchecked" />
And the code for these events is:
private void myCheckBox_Checked(object sender, RoutedEventArgs e)
{
// ...
}
private void myCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
// ...
}
EDIT: Just noticed you have the content for the checkboxes as "{Binding posID}" so something you can do (as you have a list of check boxes) is in the checked events, have something like:
if (sender != null)
{
int posID = Convert.ToInt32(((CheckBox)sender).Name);
}
This will give you the "posID" and you can do what you need too with it. :D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With