mercredi 28 novembre 2018

How to subscribe to checked/unchecked event for all checkboxes inside combobox?

I have a simple ComboBox with CheckBoxes as items. ComboBox has an item source binding to List of UserModel. The checkbox inside the ComboBox has events for checked/unchecked and has binding to isSelected Property of UserModel.

I also have button click subscribed to an event which edits data in UserModel. On the click of button appropriate checkboxes are getting checked/unchecked. While the checkboxes are checked/unchecked I also want the checkbox checked/unchecked event to be fired.

   <ComboBox x:Name="cmbUser" 
      ItemsSource="{Binding UserCollection}"
      SelectedValuePath="UserName"
      IsSynchronizedWithCurrentItem="True"
      TextSearch.TextPath="UserName">
                 <ComboBox.ItemTemplate >
                        <DataTemplate>
                                <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" Checked="UpdateSelectedUsers" Unchecked="UpdateSelectedUsers">
                                    <StackPanel Orientation="Horizontal">
                                           <TextBlock Text="{Binding UserName}" Width="105"></TextBlock>
                                    </StackPanel>
                                </CheckBox>
                         </DataTemplate>
                </ComboBox.ItemTemplate>
   </ComboBox>

I see the events are only fired when I at least open the dropdown once. So all the checkboxes inside ComboBox are loaded and subscribed to checked/unchecked event handlers.

Is there any solution to subscribe all the checkboxes inside ComboBox on the load?




Aucun commentaire:

Enregistrer un commentaire