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

前端 未结 3 1933
轮回少年
轮回少年 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:17

    What makes you think it's not working? It's working for me :)

    Here's my test XAML:

    
        
        
        

    Here's my code behind:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
    
    }
    

    (the rest is the same as yours)

    I placed a breakpoint on Button_Click and checked MyCollection[0] it was updated according to the IsChecked value of the CheckBox.

    Try changing your collection type from List to ObservableCollection perhaps that is the reason you think it's not working for you (the fact that changes to the collection are not reflected anywhere else in your view).

提交回复
热议问题