I hope I can explain this in a way that can be understood.
I have a custom control, I'll call it navigator, used to navigate
"things". I has, among other controls, two standard buttons, previous
and next. This control is implemented by other custom controls that
displays "things" in different ways. What happens when the previous
or next buttons are clicked depends on the type of parent control. To
me, this seems like a classic delegate scenario. What I'm struggling
with is the proper way to tell the navigator control which method to
use (each parent control has a method that calculates what previous or
next actually are).
What I'd like to do is create and assign the delegate inside the
navigator control with something like this:
delegate NextDelegate = new delegate(this.parent.NextThing);
This fails to compile, as the compiler has no clue how to find
"NextThing". I can deal with that.
My first inclination is to create public properties in the navigator
control and set those properties from the parent to the desired
methods when the navigator control is instantiated.
My second is to have the parent subscribe to the click event on the
navigator control buttons and handle the entire process from the
parent control. But, this forces me to put code common to all
instances of the navigator control in each parent control the
implements the navigator control (a lot of duplicate code).
The more I think about it, the more I like the first method. But,
something tells me there is some type of slick casting/typeof method
that might allow me to implement this as above. I'm interested in
other options and opinions.
Thanks,
Greg