|
HOME, PRODUCTS, ARTICLESCONTACTGLOSS CONTOUR SUITE™ FOR .NET |
![]() TOGGLE GROUP BEHAVIOR |
|
DOWNLOAD OR BUY Gloss Contour Suite™GCSuite™ FEEDBACKGCSuite™ SUPPORTC# OR .NET TECHNICAL ARTICLE FEEDBACK |
|
GlossContourButton™. |
|
HOW TO IMPLEMENT EFFICIENT TOGGLE GROUP BEHAVIOR |
|
An elementary but regular topic of UI design is how best to implement toggle group behavior — where clicking a given button leaves it in the Down state, causing the remainder of a group to revert to up. This article provides two examples — a usual tag based pattern, and a preferable generic (type safe) list based pattern, with source for both in C#. |
|
Toggle group behavior: Clicking the button on the right causes it to indicate an application condition by remaining in a Down state — reverting the remainder of the group to up. |
|
TAG STYLE TOGGLE GROUP BEHAVIOR |
|
A typical Toggle Group approach uses a common click delegate to iterate the controls of a common parent container and identify Toggle Group members by a common Tag value, setting NonSenderMember.Down to false and sender.Down to true. The downsides of this approach are,
Here, a common click delegate processes a tag value of 12345 to provide this style of toggle group behavior: |
|
C# TAG STYLE TOGGLE GROUP BEHAVIOR EXAMPLE |
|
Even in each iteration, this method requires relatively compute-intensive operations which are redundant to the generic list approach we will look at next. Because we are not using a type safe list genericized to the specific type we need to handle, substantial casting is required:
Even if we can eliminate a cast or two for a given implementation, we cannot eliminate all casts unless the list type matches our process type. A matched generic list based approach eliminates the casting issues and makes it possible to write a substantially more compact, efficient CommonToggleGroupHandler( ), as we find in the example below. |
|
PREFERABLE GENERIC LIST APPROACH TO TOGGLE GROUP BEHAVIOR |
|
A casting-free approach uses a dedicated generic list to which only a specific toggle group's members belong. The advantages of this approach are,
The following example,
|
|
C# GENERIC LIST TOGGLE GROUP BEHAVIOR EXAMPLE |
|
As we can easily see by comparing the CommonToggleGroupHandlers, the casting-free, genericized approach is substantially more efficient. As visually created examples require that you manually perform the creation and assignment aspects, this example can be considered to provide coded instructions for the equivalent visual steps. |
|
Resultant Toggle Group implementation. |
|
FIRING FURTHER PROCESSES |
|
As a matter of proper streamlining, these examples purposely exclude other possible forking. In other words, to eliminate branching logic in each iteration, and to make use of existent delegate handling processes to accomplish the same purpose, if a button's click event must invoke further processes, further delegates are attached directly to the button to do so. |
|
STATE COMPREHENSIVE PROCESSING |
|
The usual object of toggle groups is to represent application states to further processes. Branching is usually performed with nested if statements, because multiple state values are not a matter for switches. |
|
C# EXAMPLE |
|
Gloss Contour Suite™ for .NET DOCUMENTATION Introductory material and complete GCS technical documentation. HOW TO — ARTICLES AND EXAMPLE SOURCE GlossContour Suite™ INSTALLATION HOW TO IMPLEMENT EFFICIENT TOGGLE GROUP BEHAVIOR Writing efficient, type safe code to implement toggle group behavior. WALKTHROUGH 1 — DESIGNING GlossContourSurfaces™, DEPLOYING AS ContourServers™ Basic configuration of GlossContourSurfaces™ in preparation for Walkthrough 2. WALKTHROUGH 2 — DESIGNING GlossContourButtons™, DEPLOYING AS ContourServers™ OR ContourClients™ How to configure color, color offsets, gloss, glare, and 3D effects. ContourServer™/ContourClient™ implementation. NET TECHNICAL VITAL TECHNIQUES FOR USING OBJECTS AS .NET PROPERTIES Our experience with Visual Studio 2005™ demonstrates that function calls are not fired in outer set accessors of properties subject to TypeConverters. This article first revisits how to deploy TypeConverters so that your class properties will be displayed from a nested node in Properties View. It then demonstrates the necessary pattern for declaring DefaultValueAttributes, and for writing set accessors that will successfully fire vital accessor functions. |
|
|
|