public void SetStateFromCustomVariable(CustomVariable cv, IElement container, object valueToSetTo)
{
// We need to see if the state exists, and not just call SetState
// with the name of the state. The reason is because if we call SetState
// and the state is null, it will set all variables which will in turn set
// the state for the state CustomVariable which again will be null and will
// infinitely repeat.
StateSave stateToSet = GetStateSaveFromCustomVariableValue(cv, valueToSetTo);
if (stateToSet != null)
{
if (valueToSetTo is string)
{
mCurrentStateName = valueToSetTo as string;
}
else
{
mCurrentStateName = stateToSet.Name;
}
const bool refreshPositions = false;
SetState(stateToSet, refreshPositions, container);
SetCustomVariableValue(cv.Name, stateToSet);
}
}