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.