Report post

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.


Post

Posted by Nick Thissen
on
For multiple widgets: you can just loop over them. Define a list of widget names you want to change and loop over that, example below.

For integrating the dropdown: you can check which item is selected in the dropdown and get the text on that item. You can then use a kind of translation table to translate between that text and your desired color hex code. This color table is also defined in the script, but keep in mind the values in there should match to the text you put in each of the dropdown items.

In the example below I am assuming 3 items with text "Red", "Blue" and "Something else", and they map to corresponding hex codes.

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;
}
}
}