OnRenderTargetChanged()
OnRenderTargetChanged()
Definition
Called whenever a Chart’s RenderTarget is created or destroyed. OnRenderTargetChanged() is used for creating / cleaning up resources such as a SharpDX.Direct2D1.Brush used throughout your NinjaScript class.
- A RenderTarget will be created and destroyed several times during the lifetime of a chart. For example, a user resizing the chart would cause the RenderTarget to be re-created as the chart is rendered to reflect the new dimensions. Another example is when a user clicks on the chart as a RenderTarget is used during hit testing. Since there are multiple RenderTargets, you MUST ensure the resource being used belongs to the destination target. In practice, all you need to understand is if you are using a device resource (e.g., custom SharpDX Brush) throughout different event methods, you should recreate these resource during
OnRenderTargetChanged()which ensures the device resource is updated correctly as the devices context changes. - During initialization your NinjaScript indicators and strategies are guaranteed to see State.Configure before
OnRenderTargetChanged()would be called.
Method Return Value
This method does not return a value.
Syntax
You may override the method in your indicator with the following syntax:
public override void OnRenderTargetChanged() \{ \}
- Each DirectX render target requires its own brushes. You must create a brushes directly in
OnRender()or using OnRenderTargetChanged(). If you do not you will receive an error at run time similar to: “A direct X error has occurred while rendering the chart: HRESULT: [0x88990015], Module: [SharpDX.Direct2D1], ApiCode: [D2DERR_WRONG_RESOURCE_DOMAIN/WrongResourceDomain], Message: The resource was realized on the wrong render target. : Each DirectX render target requires its own brushes. You must create brushes directly inOnRender()or using OnRenderTargetChanged(). Please see the example below on using OnRenderTargetChanged() with brush that needs to be recalculated, or OnRender() for an example of recreating a static brush.
Parameters
This method does not accept any parameters.
- If you are exclusively using resources in OnRender() (e.g., not passing values from OnStateChange() or other events) you only need to create and dispose of the resource in OnRender(). The OnRenderTargetChanged() concepts illustrated below would not need to be applied.
- For a walk through for using the SharpDX RenderTarget, please see the educational resource Using SharpDX for Custom Chart Rendering.

