Click or drag to resize

ZoomPanelRegisterCustomContentProvider Method

Registers the ZoomPanel control to show custom content. With custom content the ZoomPanel does not apply scale and translate transform to its content but instead calls the customContentProvider delegate that returns the custom content based on the current zoom parameters.

Namespace:  Ab2d.Controls
Assembly:  Ab2d.Controls.ZoomPanel (in Ab2d.Controls.ZoomPanel.dll) Version: 5.2.6631.1040
Syntax
C#
public void RegisterCustomContentProvider(
	ZoomPanelCustomContentProviderDelegate customContentProvider,
	Size customContentSize
)

Parameters

customContentProvider
Type: Ab2d.ControlsZoomPanelCustomContentProviderDelegate
customContentProvider delegate that will return the custom content
customContentSize
Type: System.WindowsSize
size of the custom content
Remarks

In normal mode the ZoomPanel applies the scale and translate transform to the ZoomPanel's content. With calling the RegisterCustomContentProvider method, the ZoomPanel goes to custom content mode, which means that each time the Viewbox is changed (zoom is changed), the custom customContentProvider delegate is called to get the content that will be shown.

This is useful when the content is not static, but instead it is rendered based on the current zoom level. For example a map viewer shows the whole country map when no zoom is applied but when user zooms into the map the streets of a city can be shown.

customContentProvider delegate is called with the following parameters:

parameterdescription
relativeCustomContentViewboxThe area as System.Windows.Rect in relative coordinates that needs to be shown.
absoluteCustomContentViewboxThe area as System.Windows.Rect in absolute coordinates that needs to be shown. The absolute coordinates are based on the customContentSize that are provided with the RegisterCustomContentProvider method.
zoomLevel ZoomLevel is calculated from 1 / (relativeCustomContentViewbox.Width * relativeCustomContentViewbox.Height).
It is used to simplify deciding what kind of custom content to show (for example: country, city, street)

Example of some of the zoomLevel values:
zoomLevel = 1: no zoom applied, the whole content is shown
zoomLevel = 4: only 1/4 of the whole content is shown
zoomLevel = 10: only 1/10 of the content is shown
zoomLevel = 0.5 the shown area is twice as big as the custom content - the whole custom content is shown in the half of the available space
availableSizeThe size that is available to show the custom content. The customContentProvider delegate should return the UIElement with the same size. If the size of the returned UIElement is different, it is scaled to fill the available size.

Examples for customContentSize is 2048 x 1024:

relativeCustomContentViewbox = (0.5, 0, 0.5, 1)
absoluteCustomContentViewbox = (1024, 0, 1024, 1024)
zoomLevel = 2.0
availableSize = (100, 100)
The customContentProvider delegate should return the right half of the whole content as a UIElement with 100 x 100 points.

relativeCustomContentViewbox = (0.45, 0.45, 0.1, 0.1)
absoluteCustomContentViewbox = (921.5, 460.8, 204.8, 102.4)
zoomLevel = 100.0
availableSize = (100, 100)
The customContentProvider delegate should return the center part of the whole content with 10-times zoom applied (the width and height are 0.1 - 10% of the whole available size)

relativeCustomContentViewbox = (0, -1, 1, 3)
absoluteCustomContentViewbox = (0, -1024, 2048, 3072)
zoomLevel = 0.33
availableSize = (200, 300)

Important
In the last example the content that needs to be shown is 3 times higher than the whole custom content.
The reason to this is that the 2048 x 1024 image needs to be shown in 200 x 300 area. To do this the whole content is shown in the center of the ZoomPanel, but the area above and below the content is empty.
The following image illustrates this scenario:

The blue rectangle represents the 2048 x 1024 content scaled to fit inside the 200 x 300 area (the rectangle with black stroke). To show the content, there needs to be 100 x 100 white pixels above and below the custom content.
In this case the customContentProvider delegate should return a UIElement as it will be shown in the ZoomPanel - including the empty areas above and below the content.

Examples
The following example shows part of the code to provide the custom content to ZoomPanel.
public ZoomPanelCustomContent()
{
    InitializeComponent();

    // ZoomPanel1 is defined in xaml
    ZoomPanel1.RegisterCustomContentProvider(MyCustomContentProvider, new Size(2048, 1024));
}        

private UIElement MyCustomContentProvider(Rect relativeCustomContentViewbox, Rect absoluteCustomContentViewbox, double zoomLevel, Size availableSize)
{
    UIElement customContent;

    // TODO: Add code to create the custom content base on relativeCustomContentViewbox, absoluteCustomContentViewbox, zoomLevel and availableSize

    return customContent;
}
See Also