Q:

Access event in a user control created in code behind?

I'm trying to create a user control in my code behind, and then respond to events in that control. Presumably because the control doesn't exist at compile time, Visual Studio can't compile the handler subroutine I created to catch my control's event. Importantly, I want to decide the type of control at runtime (which is why I'm not just hard-coding it).
[before going on, the controls work correctly, including events and event handlers when used in the 'normal' way of creating the controls in XAML. I want to create the control instances in code behind so I can avoid duplicating pages that are 99% identical]
This 'works' (but doesn't give me the flexibility I need):
        Public WithEvents AnswerPanel As MyControls.ScrollerControl

... (and the initialisation in the New() sub):
        AnswerPanel = New MyControls.ScrollerControl
        ItemStack3.Children.Add(AnswerPanel)

        AddHandler AnswerPanel.GuessMade, AddressOf CheckAnswer

... (this is the handler sub responding to a custom event in the ScrollerControl)
        Public Sub CheckAnswer(answer As String) Handles AnswerPanel.GuessMade

With the code above everything works as I expect: the control is created at runtime and its event is handled correctly.
What I want to achieve is to be able to choose a different user control when I initialise my control (e.g. ScrollerControl2, ScrollerControl3, etc.) I can create the controls this way by changing the first line to:
        Public WithEvents AnswerPanel As UserControl

But once that change is made I can no longer reference the custom event in my handler as (presumably) the compiler sees it as a generic UserControl, which doesn't include my custom GuessMade event. The compiler errors on the event name and tells me it doesn't exist.
I'm sure I'm doing something wrong here. I think it's a theory/concept issue rather than my code.
Am I on the right track or going about this in the wrong way?

A:

I have an answer to this now. As I suspected I was sort of thinking about the problem from the wrong angle.
In a nutshell I was trying to raise an event from my user controls, but I needed to be raising the events in the base class and calling that from my user controls.
So my base class (which my user controls inherit from), now contains the following:
    Public Event GuessMade(answer As String)

    Protected Sub RaiseGuessEvent(answer As String)

         RaiseEvent GuessMade(answer)

    End Sub

Then, in my user control(s), when I need to raise the event, I simply call the RaiseGuessEvent sub like this:
     Me.RaiseGuessEvent(CurrentValue)

And additionally, I had to remove the event from my subclasses/user controls, of course.

