views:

23

answers:

1

Hi all, I'm trying to write a class that I can use to interact with a group of similar controls in my wpf application. I have hit a few roadblocks and now I am wondering if this is a poor approach to begin with.

I want to do this primarily to make my code more manageable - I have to interact with around 200 - 300 controls with my code, and it could get very tricky to have all my code in the main window class.

Here's something I'd like to be able to do:

    class ProcControl
    {
        private CheckBox * [] Boxes = new CheckBox[10];

        ProcControl()
        {
            //set boxes 0-9 to point to the actual checkboxes
        }

        //provides mass checking/unchecking functionality
        public void Refactor(CheckBox box)
        {
            //see what box it is
            int box_index = 0;
            while (Boxes[box_index] != box) { box_index++; }
        }
    }

This doesn't work as it is right now. I have not figured out how to get my Boxes[] array to point to the actual checkboxes on my form, so I can't interact with them yet.

Is it even possible to make an array that points to a bunch of controls so that I may process their properties in a nice manner?

Why can't I access the controls at all from inside my class?

+1  A: 

Pass the array of boxes into your control in the control's constructor...

class ProcControl
{
    protected CheckBox[] Boxes { get; private set;}

    ProcControl(CheckBox[] boxes)
    {
        Boxes = boxes;

     }

   //...
}

You will need to add the control to your form dynamically, after the CheckBoxes have been created and write a method on your form that identifies all of the relevant controls and passes them to the ProcControl in its constructor.

Daniel Dyson