Bind a control to a single value in a collection/array in WPF

前端 未结 3 1918
轮回少年
轮回少年 2021-01-06 09:53

In WPF I have a collection of bool? values and I want to bind each of these to a separate checkbox programmatically. I want the bindings to be TwoWay so that changing the va

3条回答
  •  攒了一身酷
    2021-01-06 10:13

    Change your List to an ObservableCollection. A List does not raise the change notifications that WPF needs to update the UI. An ObservableCollection does. This handles the case where the list entry is changed and the CheckBox needs to update accordingly.

    In the other direction, it works for me even with a List -- i.e. toggling the checkbox modifies the value in the collection. Your binding syntax is certainly correct.

提交回复
热议问题