Performing side-effects in conversion functions is still a bad idea. (Other than setting the target property, of course.)
In this case you still do not know how often or when your addGroupIcon
function will be called. Try putting in an alert
and you will see how many copies of the Picture are added as the app is used. But I do not understand when you want that group icon to be added. Why isn’t it there as part of the template? You can toggle its visible property if you want to show or hide it at different times.
Regarding that other issue, just make sure that Group.isSubGraphExpanded is set to false, if you want the group to start off collapsed.