OnRenderTargetChanged()
<< Click to Display Table of Contents >> OnRenderTargetChanged() |
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.
Notes: 1. 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. 2. During initialization your NinjaScript indicators and strategies are guaranteed to see State.Configure before OnRenderTargetChanged() would be called. |
This method does not return a value.
You may override the method in your indicator with the following syntax:
public override void OnRenderTargetChanged()
{
}
Warning: 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:
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. |
This method does not accept any parameters
Tips: 1.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. 2.For a walk through for using the SharpDX RenderTarget, please see the educational resource Using SharpDX for Custom Chart Rendering |
Recalculating a SharpDX Brush conditionally in OnBarUpdate() |
---|
private SharpDX.Direct2D1.Brush dxBrush = null; // the SharpDX brush used for rendering |
Recalculating a SharpDX Brush based on user input |
---|
private SharpDX.Direct2D1.Brush dxBrush = null; // the SharpDX brush used for rendering
[XmlIgnore]
[Browsable(false)] |