After digging a bit deeper I found that all those classes inherit from the DSDropDownBase class, but I still cannot make this work correctly.
If the constructur is commented out (I found this by accident) I can almost get the GUI working with the options shown in the dropdown, however the node throws an error. If the constructor is in the code, the node does not show up in Dynamo at all. Does anyone have a clue what I’m doing wrong there?
public class DummyDropdown : DSDropDownBase
{
//Only if comment this line out, does the node show up in Dynamo but does not work.
protected DummyDropdown() : base("Selection") { }
protected override SelectionState PopulateItemsCore(string currentSelection)
{
Items.Clear();
Dictionary<string, int> dropdownItems = new Dictionary<string, int> {
{ "Test1", 1 },
{ "Test2", 2 },
{ "Test3", 3 },
{ "Test4", 4 },
};
foreach (KeyValuePair<string, int> item in dropdownItems)
{
Items.Add(new DynamoDropDownItem(item.Key, item.Value));
}
return SelectionState.Restore;
}
public override IEnumerable<AssociativeNode> BuildOutputAst(List<AssociativeNode> inputAstNodes)
{
return new[] { AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), AstFactory.BuildIntNode((int)(Items[SelectedIndex].Item))) };
}
}