Tuesday, August 25, 2015
Getting ready the ConditionalAppearance module infrastructure for custom options of the extended AppearanceAttribute (e.g., tooltip)
First of all, this piece of information is quite advanced, so be sure you are well-aware of the module's basic functions and main extensibility and customization points, at least through AppearanceController. If not, check out the related online documentation before reading further.
Would it be possible to add in the conditional appearance module the possibility to show a tooltip in the cell in listView when the
condition is satisfied? (you get different color based on criteria and when you move to the cell a tooltip is shown telling you why the color is different ), example:
Alternative solution considerationsIf there were no ready built-in module in XAF, you could solve this by using the pure means available for the underlying grid control for a target platform. For instance, in WinForms, you could employ the ToolTipController API, while for ASP.NET WebForms you could handle the ASPxGridView events to programmatically assign a tooltip text to required data cells. Apparently, making these custom-tailored control-based solutions universal would require effort without XAF, and XAF users could even see this work as a duplication of the perfect existent infrastructure ConditionalAppearance provides. So, let's describe how to do things the XAF way!
Let me repost the answer my colleague provided in the original SC ticket and then elaborate more on the technical aspects of this solution:
AppearanceWithToolTipAttribute.cs - contains a definition of an AppearanceAttribute descendant with a custom ToolTip property (its sample use is shown in the Class1.cs file) as well as several required service classes to propagate this new option through the Application Model and the whole ConditionalAppearance module infrastructure. For instance, the AppearanceItemToolTip class is an AppearanceItemBase descendant that serves the same role as AppearanceItemEnabled, AppearanceItemFontColor and other built-in implementations (here it solely holds a tooltip value).
The IModelAppearanceWithToolTipRule interface and its domain logic define a custom Application Model element that extends the built-in IModelAppearanceRule with the ToolTip property (see the Module.cs file for the registration code).
Finally, the ToolTipAppearanceRule class is a descendant of the service AppearanceRule class with a single overridden method that instantiates AppearanceItemToolTip objects for IModelAppearanceWithToolTipRule nodes defined by a user in the Application Model.
AppearanceGridViewToolTipController.cs - contains a ViewController that handles the CustomCreateAppearanceRule and ApperanceApplied events of the built-in AppearanceController for connecting rule metadata information with the underlying control customizations. In other words, the information from the AppearanceItemToolTip entity is propagated to the built-in TableCellAppearanceAdapter object, which represents a precise implementation of the IAppearanceFormat interface (there are various implementations for different UI entities in XAF). Or, simply, a link between the underlying UI control and its TableCell object to which various appearance options (font, color, tooltip) can be applied.