Container Controls and Page Panel

Hello,

I am learning Xojo and ran into something that is puzzling me. I’ve searched both Google and the Xojo forums, but I haven’t been able to figure this one puzzle out yet. Hmm… :wink:

I have the following:

  • A Page Panel
  • Two Container Controls.

The page panel has two “pages” in it. I figured it would be neat if I could add the first container control to the first page … and the second container control to the 2nd page.

In the first container control, I added a button (that when the user clicks it), the Page Panel should switch from displaying the first page to the second one. However, I can’t seem to access the Page Panel’s properties from the button’s “Action” method.

I’m sure that it’s probably an encapsulation issue, but I can’t seem to figure out how to access it. I tried using the “me”, “self”, and “parent” prefixes, but without any lucky. Any guidance or suggestions?

You cannot access outside of a ContainerControl unless you have an explicit reference to the view you want to access. For instance, you can do something like

Window1.PagePanel1.Value = 1

and while it will work, it’s not necessarily correct. Typically, you want to add an event definition to your ContainerControl that is raised when the user clicks the button, then implement a handler for that event in your main view to perform the actual change.

You could also track the parent view in a property of the ContainerControl and set it from your parent view, something like

Public Property myPagePanel as PagePanel

but the former manner is much better.

If you move the mouse pointer over ‘Me’ or ‘Self’, the IDE will tell you what those values are:


If you put the Button on the PagePanel instead of the container control, this code in Action event could work:

PagePanel1.Value = 1

As @Alberto DePoo said, inside a PushButton’s Action event which resides within a ContainerControl, Me would refer to the button and Self would refer to the ContainerControl. ContainerControls are actually what’s called internally "EmbeddedWindowControl"s. In most all aspects they behave and should be considered windows. They are entirely separate environments from whatever view you place them on.

You can also use TrueWindow to reference the actual enclosing window.

IMO and as @Anthony Cyphers said, you should encapsulate the container and to do this you would:

  1. Add an event definition to the container called say “NextPage”.
  2. In the button action event RaiseEvent NextPage.
  3. In the Window add an event handler to your container and increment the value of PagePanel1.

You could add the button to the page panel instead of the container, but in all probability you’ll want to enable the button based on data entered and then you end up with the same scenario - instead of a NextPage event you create a EnableNextPage event.

Thank you! I appreciate your insightful help! I learned some new things… :slight_smile:

Of course Anthony is correct, the above screen captures were from a PushButton inside the PagePanel.

Here is a button inside a container, Self refer to ContainerControl1: