Phone1.800.366.3472 SupportGet Support DocumentationDocumentation Resource CenterResource Center
Open Menu

Synergex Blog

I Command Thee

By Richard Morris, Posted on June 12, 2012 at 7:10 am


At the DevPartner conference in Chicago ( we announced an open source project called Symphony Framework.  The Symphony Framework project is a Synergy .NET based set of libraries that assist with the migration of traditional Synergy cell based and UI Toolkit applications to a native .NET Windows Presentation Foundation (WPF) desktop application.  The concept of the Symphony Framework is to simplify the Model-View-View Model (MVVM) design pattern and make it easy to migrate your traditional Synergy code.

An important aspect of any program is responding to user requests.  In a UI Toolkit program this is typically based on menu entries – even ones that don’t exist and are signalled in code using M_SIGNAL().  A WPF desktop application is no exception and commanding is an important aspect of the program.  In the MVVM model you utilise an interface called ICommand.  This interface provides for three very important elements.  Firstly, a hook, or entry point to be executed when the command is processed.  Processing a command can be assigned to the click of a button on the UI, it could be the navigation event around a list, or even a line of code in your program.  Secondly the ICommand model enables a status enquiry point –where the bound UI control can interrogate the command object and determine if it is enabled for execution.  Generally a UI control bound to a command object will render itself differently depending on the executable state of the command.  For example a button will appear greyed out and not clickable.  And thirdly is the ability to notify the UI control that the executable status of the command has changed, which causes the interrogation of the command object to determine is executable state.

The Symphony Framework exposes a number of command types, the easiest to use is the GenericCommand, which can be found in the Symphony.Conductor.Commands namespace.  This class utilises the ICommand interface and makes coding commands very simple.  You can create individual command objects or one generic command.  Here is an example of defining a generic command within your View Model class that can be bound to any number of UI control.

Firstly, reference the correct namespace:

Now create a private class member:

Now expose a public property which we can bind out UI control to:

Note in this code that if the private mCommand class field is null we create an instance of the GenericCommand class and assign it.  We also define the logic to execute when the command is processed.  Now we can write the event handler:

Notice the routine signature.  The “parameter” string argument will be set to the value you assign to the bound command in the UI.  As an example, here we are defining three buttons which all data bind to the Command property:

By using the CommandParameter attribute we can assign the required “operation” to each bound command.  Now we can extend the logic in our event handler routine:

This example shows you how to easily utilise the GenericCommand class within the Symphony Framework.

There are many more examples that you can review from the Examples Explorer which is available when you install the full Symphony Framework.  If you are interested in looking at the Symphony Framework code and becoming part of the development community search for “Symphony Framework”.

Leave a Reply

Your email address will not be published. Required fields are marked *


Recent Posts Categories Tag Cloud Archives