White Papers: Events, In-line Code, and Code-Behind
Contents
MyXaml implements a parser that can instantiate any class in a given namespace and assembly. Utilizing in-line or out-of-line source files in conjunction with the application, a rich environment is created for managing events and class derivation.

In this scenario, there is no code behind and the markup doesn't specify any events itself. Here, the application must wire up any event handlers programmatically, just as is done in regular development.

In this example, the generator manages the wiring of events automatically. The event is specified in the markup along with the method name in a class instance specified by the application. Of course, nothing prevents the application from programmatically wiring up other events.

In this example, the application does not provide an event context. It must wire up events programmatically. Also, since there is code-behind defined in the markup, the events can be handled by the code-behind instead of the application.

In this example, both the application and the code-behind event handlers are wired by events specified in the markup, and both participate in handling the events.

This is an example of how child controls (or collections in general) are instantiated, and how events can be handled by both the application and code-behind context for both the main form and the child controls. This diagram assumes that all children are specified inline.

This example is a bit more complicated. Here, we have child controls that are specified with separate canvases, allowing the child to have unique code-behind for managing events.

Finally, instead of specifying the form base as a class in the System.Windows.Forms namespace (or other namespace), you can specify the form base to be of the class defined in the code-behind. As long as the code-behind class is derived from the appropriate class, you can set properties and events in both the code-behind and the super-class.
Using MyXaml as a markup parser and general purpose class instantiator creates a very flexible and rich environment. This flexibility makes it easy to change the behavior of your application while at the same time keeping a clean separation between presentation and state management.
©2004 - 2008 MyXaml. All Rights Reserved.
|