0

I've created a list of check boxes and bound them as shown below.

<ListBox ItemsSource="{Binding AllCarrierTypes}">
  <ListBox.ItemTemplate>
    <DataTemplate>
      <CheckBox Content="{Binding Name}"
                IsChecked="{Binding Active,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                Checked="ToggleButton_OnChecked"
                Unchecked="ToggleButton_OnUnchecked"/>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

However, when I breakpoint on the unchecked event and see the contents of AllCarrierTypes, using Where() to only get the actives, I see that the list stays the same, despite the fact that those small thingies in the GUI actually are on and off. What can I do to troubleshoot it? According to the things I've read and seen, it supposed to work, so it's likely something stupid I've forgotten...

11
  • Have you tried a simpler example? <CheckBox Content="{Binding Name}" IsChecked="{Binding Active}"/>? What do those event handlers do?
    – nvoigt
    Jan 17, 2015 at 20:53
  • Please post your view model code.
    – dymanoid
    Jan 17, 2015 at 20:55
  • I was told that, it needed to be a two-way because I'm reading in values in the itnitializer setting the boxes. And specifying update source trigger was suggested as a possible remedy in another thread (where I asked about another issue, which seems to be dependent on this one). The handlers are there because the data grid needs to get the filter set explicitly (some issue in .NET, according to some guy). Jan 17, 2015 at 20:55
  • @dymanoid Is there anything specific you'd like to verify there? I've posted it already in another thread's edit and it feel to me like spamming SO with it. :) Jan 17, 2015 at 20:59
  • 1
    You should not rely on the order in which things happen here. Although your Unchecked handler is called, the IsChecked binding to the respective view model item might not have been triggered yet. Remove the Checked and Unchecked handlers, and move their code to the setter of the Active property in your view model. Or at least ode the view model related code to the view model.
    – Clemens
    Jan 17, 2015 at 21:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.