Version

Creating the Custom View Class and Layout Panel

Custom View Class

The Custom View class itself doesn’t normally do any 'work'. Its main purpose is to override ViewBase properties and methods to provide enough information for xamDataPresenter™ to customize its Field and element generation process to suit the needs of your Custom View. The Custom View’s Layout Panel (see below) does the lion’s share of the work required to implement the view.

Optionally, your Custom View can expose one or more properties to let the developer control important aspects of the Custom View’s functionality. If your View has only one or two properties to expose, it can expose them directly on the Custom View class itself. If the Custom View needs to expose more properties, you may want to consider doing what the built-in GridView and CarouselView classes do, which is to expose a single property called ViewSettings that returns a settings object derived from ViewSettingsBase. This reduces clutter on your Custom View class and exposes your view’s functionality in a way that developers are familiar with.

Custom View’s Layout Panel

Your Custom View’s Layout Panel is responsible for arranging items on behalf of your View. This is where the bulk of your Custom View’s "magic" happens. The primary purpose of a Custom View is to provide a unique UI for displaying the elements that are automatically generated by xamDataPresenter. These generated elements are used in the UI to represent the records and fields in the underlying data source. Your Layout Panel is the where this unique UI is assembled and displayed.

Your Layout Panel will normally override the OnPropertyChanged method, looking for a notification that the DataPresenterBase.CurrentView attached property has changed. This attached property, set by xamDataPresenter on your Layout Panel when it is created, will contain a reference to an instance of your Custom View class. This is your layout Panel’s "link" to your Custom View and any settings that may it may expose. (This instance of your Custom View class is the same instance the developer set on xamDataPresenter’s View property to start the process of using your Custom View.)

While your Layout Panel will inherit functionality from the base Panel class that automatically communicates with xamDataPresenter’s embedded RecordListBoxControl to generate UI elements for each DataRecord in the underlying data source, it will not automatically pick up support for virtualizing those generated elements (i.e., cleaning them up when they are scrolled out of view). To ensure optimal performance especially when binding to large data sets, you should consider deriving your Layout Panel from System.Windows.Controls.VirtualizingPanel to inherit basic support for virtualizing generated elements.