Are you sure you want to report the post shown below? This will send an email to the ATVO administrators. Please include a short reason for reporting.
Users reporting for no reason may be locked out.
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using System.Windows.Media;
using System.Collections.Generic;
namespace Scripts
{
public class ChangeColor : IScript
{
// Define the names of the widgets you want to change
private string[] _widgetNames = new string[]{
"Widget1", "Widget2", "Widget3"
};
// Define a color table that translates your dropdown item text to a color hex code
private Dictionary<string, string> _colorTable = new Dictionary<string, string>() {
{"Red", "FF0000"},
{"Blue", "0000FF"},
{"Something else", "FF00AA"},
};
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Find the dropdown
var dd = (Dropdown) item.Theme.Dropdowns.Find("Dropdown1");
if (dd.SelectedItem == null)
return null;
// Find the text of its selected item
var selectedText = dd.SelectedItem.Text;
// See if there is a corresponding entry in the color table
if (!_colorTable.ContainsKey(selectedText))
{
Console.WriteLine("Missing entry in color table: " + selectedText);
return null;
}
// Get the color value from the table and convert it to a color
var colorValue = _colorTable[selectedText];
var color = (Color)ColorConverter.ConvertFromString(colorValue);
// Loop over all widgets and change their background
foreach (var name in _widgetNames)
{
var widget = item.Theme.Widgets.Find(name);
if (widget != null)
{
widget.Background.BackgroundColor = color;
}
}
return null;
}
}
}