How to adapt a custom extension to the current theme

How to adapt a custom extension to the current theme

book

Article ID: KB0076713

calendar_today

Updated On:

Products Versions
Spotfire Analyst 7.5 and Higher

Description

You can use the Document.GetStyle() method to get the style properties of elements in the user interface. There are various related classes such as StyleProperties, ColorInfo, FontStyle, FontWeight etc. See the attached image (Filename:Styling API.png) to get a brief idea about these classes.

Issue/Introduction

This article describes how to adapt to the current theme in custom visualizations or custom extensions.

Resolution

In the RenderCore() of the CustomVisualization you can use the Document.GetStyle() to get the current theme of the Analysis and then use this in the visual to adapt.

Example:
var visualContentStyle = document.GetStyle(StyleElement.VisualContent);
            var backgroundColor = visualContentStyle.GetEffectiveBackgroundColor();
            using (Brush backgroundBrush = new SolidBrush(backgroundColor))
            using (Pen backgroundPen = new Pen(backgroundColor))
            {
                renderArgs.Graphics.DrawRectangle(backgroundPen, renderArgs.Bounds);
                renderArgs.Graphics.FillRectangle(backgroundBrush, renderArgs.Bounds);
            }
Refer to the RenderCore() in the TrafficLightchart.cs or CustomScatterPlot.cs of the CustomVisualsExample available with the SDK on how to manage the visualizations to blend in with the theme in the analysis.

Additional Information

Documentation: 

Attachments

How to adapt a custom extension to the current theme get_app