# Activate State on StateGroup programmatically

**URL:** <https://forums.fusetools.com/t/activate-state-on-stategroup-programmatically/1497>\
**Category:** How-to Discussions\
**Created:** [May 21, 2015, 1:51pm UTC](https://forums.fusetools.com/t/activate-state-on-stategroup-programmatically/1497 "2015-05-21T13:51:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_Inge\_Asbjornsen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/sean_inge_asbjornsen/32/578_2.png) [@Sean\_Inge\_Asbjornsen](https://forums.fusetools.com/u/Sean_Inge_Asbjornsen)\
**Post date:** [May 21, 2015, 1:51pm UTC](https://forums.fusetools.com/t/activate-state-on-stategroup-programmatically/1497/1 "2015-05-21T13:51:37Z")

</div>

I’m trying to activate a State on a StateGroup from Uno code. The documentation says that changing StateGroups Active property will initiate the transition, so thats what I tried to do in my ‘Navigate’ function. Any ideas why this isn’t working?

public partial class TabViewer

{

```auto
List<TabContent> mContent = new List<TabContent>();

StateGroup mTabGridStateGroup = new StateGroup();

public TabViewer()
{
    InitializeUX();
    mxTabGrid.Behaviors.Add(mTabGridStateGroup);
}

public void AddContent(TabContent content)
{
    //Add State
    State state = new State();
    Move move = new Move();
    move.Target = mxTabRectangle;
    move.X = mContent.Count;
    move.RelativeTo = TranslationMode.Size;
    move.Easing = Easing.SinusoidalInOut;
    move.Duration = 0.3;

    state.Animators.Add(move);
    mTabGridStateGroup.States.Add(state);

    mContent.Add(content);

    //Resize TabRectangle
    mxTabRectangle.Width = 100.0f/mContent.Count;

    //Add button to TabBar
    mxTabGrid.ColumnCount = mxTabGrid.ColumnCount + 1;
    Z_NavButton button = new Z_NavButton();
    button.Clicked += Navigate;
    button.Text = content.Title;
    mxTabGrid.Children.Add(button);
}

void Navigate(object sender, ClickedArgs args)
{
    Button button = sender as Button;

    for(int i = 0; i < mContent.Count; i++)
    {
        if(button.Text == mContent[i].Title)
        {
            mxTabNavigation.Goto(mContent[i].PageForTab);
            mTabGridStateGroup.Active = mTabGridStateGroup.States[i];
            break;
        }
    }
}

```

}

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [May 21, 2015, 2:53pm UTC](https://forums.fusetools.com/t/activate-state-on-stategroup-programmatically/1497/2 "2015-05-21T14:53:32Z")

</div>

Hi!

It is reccommended to do this from UX code instead of Uno code, this will make it easier to see what the code does.

I don’t see anything directly wrong. Are you sure the `mTabGridStateGroup.Active = mTabGridStateGroup.States[i];` line is actually reached?

---

<div class="post-metadata">

**Author:** ![Sean\_Inge\_Asbjornsen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/sean_inge_asbjornsen/32/578_2.png) [@Sean\_Inge\_Asbjornsen](https://forums.fusetools.com/u/Sean_Inge_Asbjornsen)\
**Post date:** [May 21, 2015, 5:07pm UTC](https://forums.fusetools.com/t/activate-state-on-stategroup-programmatically/1497/3 "2015-05-21T17:07:42Z")

</div>

Yes, because mxTabNavigation.Goto is called.

The reason i am doing this in Uno is because states can be added at runtime.

---

<div class="post-metadata">

**Author:** ![edA-qa\_mort-ora-y](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/eda-qa_mort-ora-y/32/124_2.png) [@edA-qa\_mort-ora-y](https://forums.fusetools.com/u/edA-qa_mort-ora-y)\
**Post date:** [May 21, 2015, 5:19pm UTC](https://forums.fusetools.com/t/activate-state-on-stategroup-programmatically/1497/4 "2015-05-21T17:19:36Z")

</div>

You can verify whether a trigger/state is actually activated by using a `DebugAction` action.

```auto
<State ...>
    <DebugAction Message="Made it"/>
</State>

```

If that is output it means you at least arrive at that state. Then it is a matter of figuring out why the other animator doesn’t do what you expect. My guess is the `Move` is perhpas not attached to the intended element.

It might be good to explain what you are trying to achieve. It seems that you might be trying to replicate functionality similar to the `PageControl` and the rectnagle might be a `PageIndicator`.

---

<div class="post-metadata">

**Author:** ![Sean\_Inge\_Asbjornsen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/sean_inge_asbjornsen/32/578_2.png) [@Sean\_Inge\_Asbjornsen](https://forums.fusetools.com/u/Sean_Inge_Asbjornsen)\
**Post date:** [May 22, 2015, 7:21am UTC](https://forums.fusetools.com/t/activate-state-on-stategroup-programmatically/1497/5 "2015-05-22T07:21:25Z")

</div>

I can’t find any reference to a PageControl or PageIndicator in the documentation. Is this perhaps something that has not yet been released?

EDIT: I downloaded the newest release and ran the guide for PageControl. I am trying to make a component that has the same functionality, but i would also like the indicators to be buttons that navigates to the correct page. Is there anyway to achieve this with PageControl?
