lundi 3 août 2015

WPF/C# entirely programmatically binding an array of objects to a static ObservableCollection

Please assume this entire question deals in code, without any XAML.

I have a static ObservableCollection named myStaticList. It's a part of a non-static class named myClass.

public class myClass
{
    public static ObservableCollection<CheckBoxStructure> myStaticList { get; set; }

    static myClass()
    {
        myStaticList = new ObservableCollection<CheckBoxStructure>();
    }
}

And the definition of CheckBoxStructure:

public class CheckBoxStructure
{
    public string Description { get; set; }
    public bool IsSelected { get; set; }
}

In addition, there's an array of checkboxes called checkBoxArray[], holding 3 elements. each checkbox has as content a textbox.

What I want to do is programmatically bind (two-way) these two, in such a manner that the IsChecked property of the checkboxes in the checkBoxArray[] array will bind to the IsSelected property of the myStaticList's CheckBoxStructure, and similarly so between the text of the textboxes inthe checkboxes' content and the Description property of the myStaticList's CheckBoxStructure.

In addition, I would like to avoid using loops, since it is preferable that this two lists will update each other if they change in size.

How is this possible?

Thanks!




Aucun commentaire:

Enregistrer un commentaire