DevForce does not provide user interface (UI) components but it does provide fundamental features that facilitate the display of entities on a variety of .NET client platforms and works well with 3rd party UI controls as well as native Microsoft controls. We mean "display" in the broad sense of presenting the entity to a user and updating the entity with user input. The core UI supporting features are the subject of this section.
DevForce applications run on all of the principal .NET client platforms: ASP.NET, Windows Forms, Windows Presentation Foundation (WPF), Silverlight, and Windows Phone 7.
DevForce entities are equipped for direct presentation in the user interface (UI) primarily through support for standard .NET data annotations and data binding interfaces.
Data annotation define metadata about objects and their properties that the UI can read to determine how to display those objects. These annotations are described in MSDN documentation for the System.ComponentModel.DataAnnotations namespace.
Data annotations are .NET attributes applied to classes and property members. DevForce can generate some of them for your entities based on the Entity Data Model (EDM). The developer can add more by adding them to the custom entity class and an optional companion Entity Metadata Class as described in the Model section.
The Display attribute, for example, suggests text for the label next to a TextBox or the header for a grid column. UI controls that detect the Editable attribute can configure controls to permit or refuse user input. Numerous data annotation attributes such as Required, Range, and RegularExpression, define validation rules that the UI could enforce.
ASP.NET MVC, ASP Dynamic Controls, WPF, and Silverlight clients all make good use of data annotations.
Data binding links UI controls to properties of a data object. When a UI control is bound to a data object property, the control pulls values from the data object and pushes user entered values back into the data object automatically.
Data binding is the primary mechanism for presenting data to Windows Forms, WPF, and Silverlight screens.
The developer sets up the binding between the UI control and data object property - we say that she "binds" the control to the data object property - and the data binding infrastructure does the work. WPF and Silverlight share common techniques for binding controls to data and it is these XAML platforms that we'll address in this section although most of what we say about the data binding interfaces applies to Windows Forms clients as well.
Data binding works if the two sides - control and data object - are implemented to support it. The UI technology you've chosen determines the control side of that equation. Whether the data object is bindable - and what data binding feature it supports - depends upon characteristics of the data object, most especially what .NET data binding interfaces it supports.
When your entities derive from the DevForce entity class, they support the following data binding interfaces:
INotifyPropertyChanged - Tells the listener when the value of a property has changed. UI controls listen for PropertyChanged and update with the latest value of the bound data property. Every DevForce generated property is wired to raise PropertyChanged when updated with a new value.
IEditableObject - A UI control can ask the entity to begin a mini-editing session during which the entity accepts all changes from that control provisionally. In effect, the entity maintains a snapshot of the property values as they were before the mini-session began. If the user cancels the changes made during the mini-session, the entity rolls the state of the entity back to the snapshot. When the user does something to accept the changes (that "something" is up to the control), the control tells the entity to "commit" those changes; the entity then moves the changes from "provisional" to "current" value status. Note that the entity remains in a modified state, as the changes haven't been saved to the database. The entity's original values are still available if the entity was pre-existing (i.e., it had been retrieved from the database before being modified).
INotifyDataErrorInfo- When DevForce entities are validated (see Validate), DevForce uses its implementation of this interface to make the validation results available to the UI and also notifies the UI that validation results have changed. This is a Silverlight-only interfaces as of .NET 4.
IDataErrorInfo- This is an alternative interface for making validation results available to the UI. It's different from INotifyDataErrorInfo, most conspicuously in lacking the notification event. Windows Forms and WPF controls recognize this older interface; Silverlight does not. DevForce supports all three client platforms by implementing both IDataErrorInfo and INotifyDataErrorInfo.
INotifyCollectionChanged- Entity collection navigation properties (e.g, Customer.Orders) return a list of entities. More specifically, they return a RelatedEntityList<T>. RelatedEntityList implements this interface which tells the UI when items are added or removed or the entire list is refreshed.
WPF and Silverlight developers benefit from design tools (such as Blend) that can display "design data" as you layout the screens.
Several IdeaBlade presentations, videos, and code samples demonstrate techniques for designing screens and views using DevForce entities and offline EntityManagers. A good place to start is the BookShelfSilverlight Reference application.
You may want to use the Data Sources Window built into Visual Studio to simplify binding to your entities at design time. To do so, you must configure Visual Studio to connect to data in the object, with the followign steps:
This provides certain advantages by allowing you to generate more of your design with tools, but has several drawbacks. These include: