locked
Change active tab in code

    Question

  • Is there a way to change the currently active tab in the Tab Layout group in code? I am planning to automatically select the initial active tab for the user depending on where a screen is called from.
    Thursday, April 14, 2011 7:47 AM

Answers

  • This will change the active tab within a screen:

    // add reference to TabControl library
    using System.Windows.Controls;

    // screen created method
    partial void YourScreen_Created()
    {
        var proxy = this.FindControl("YourTabControl");
        proxy.ControlAvailable += new EventHandler<ControlAvailableEventArgs>(YourTabControl_ControlAvailable);
    }

    // change tab index once tab control becomes available
    void YourTabControl_ControlAvailable(object sender, ControlAvailableEventArgs e)
    {
        var tabControl = (TabControl)e.Control;
        tabControl.SelectedIndex = 1;  // 0=first tab, 1=second tab, etc
    }

    Regards


    Xander

    • Proposed as answer by novascape Thursday, April 14, 2011 9:34 AM
    • Marked as answer by James EJ Thursday, April 14, 2011 10:32 AM
    Thursday, April 14, 2011 9:33 AM

All replies

  • This will change the active tab within a screen:

    // add reference to TabControl library
    using System.Windows.Controls;

    // screen created method
    partial void YourScreen_Created()
    {
        var proxy = this.FindControl("YourTabControl");
        proxy.ControlAvailable += new EventHandler<ControlAvailableEventArgs>(YourTabControl_ControlAvailable);
    }

    // change tab index once tab control becomes available
    void YourTabControl_ControlAvailable(object sender, ControlAvailableEventArgs e)
    {
        var tabControl = (TabControl)e.Control;
        tabControl.SelectedIndex = 1;  // 0=first tab, 1=second tab, etc
    }

    Regards


    Xander

    • Proposed as answer by novascape Thursday, April 14, 2011 9:34 AM
    • Marked as answer by James EJ Thursday, April 14, 2011 10:32 AM
    Thursday, April 14, 2011 9:33 AM
  • Awesome. Thanks.
    Thursday, April 14, 2011 10:33 AM