Version

ExecuteCommand Method (XamTabControl)

Executes the specified RoutedCommand.
Syntax
'Declaration
 
Public Function ExecuteCommand( _
   ByVal command As RoutedCommand _
) As Boolean
public bool ExecuteCommand( 
   RoutedCommand command
)

Parameters

command
The RoutedCommand to execute.

Return Value

True if command was executed, false if canceled.
Example
The following shows how to use the commands exposed by the TabControlCommands class.

<Window x:Class="XamTabControl_cs.Window1"
    
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    
Title="Window1" Height="414" Width="670" 
    
xmlns:igThemes="http://infragistics.com/Themes" 
    
xmlns:igWindows="http://infragistics.com/Windows">
     
<Grid>
        
<Grid.RowDefinitions>
            
<RowDefinition/>
            
<RowDefinition Height="Auto"/>
        
</Grid.RowDefinitions>

        
<Grid Grid.Row="0" >
            
<igWindows:XamTabControl Name="xamTabControl1">

                
<igWindows:TabItemEx Header="tabItemEx1" Name="tabItemEx1" >
                    
<Grid /> <!-- tab item content goes here -->
                
</igWindows:TabItemEx>

                
<igWindows:TabItemEx Header="tabItemEx2" Name="tabItemEx2" >
                    
<Grid /> <!-- tab item content goes here -->
                
</igWindows:TabItemEx>

             
</igWindows:XamTabControl>
        
</Grid>

        
<Grid Grid.Row="1">
            
<Grid.ColumnDefinitions>
                
<ColumnDefinition Width="Auto"/>
                
<ColumnDefinition/>
                
<ColumnDefinition/>
                
<ColumnDefinition/>
                
<ColumnDefinition/>
                
<ColumnDefinition/>
            
</Grid.ColumnDefinitions>
            
<Grid.RowDefinitions>
                
<RowDefinition/>
                
<RowDefinition/>
            
</Grid.RowDefinitions>

            
<Label Grid.Column="0">XamTabControl Commands:</Label>

            
<Button Grid.Column="1" Grid.Row="0" 
                    
Command="igWindows:TabControlCommands.SelectFirstTab" 
                    
CommandTarget="{Binding ElementName=xamTabControl1}">
                Select_FirstTab
</Button>

            
<Button Grid.Column="2" Grid.Row="0" 
                    
Command="igWindows:TabControlCommands.SelectLastTab" 
                    
CommandTarget="{Binding ElementName=xamTabControl1}">
                Select_LastTab
</Button>

            
<Button Grid.Column="3" Grid.Row="0" 
                    
Command="igWindows:TabControlCommands.SelectNextTab" 
                    
CommandTarget="{Binding ElementName=xamTabControl1}">
                Select_NextTab
</Button>

            
<Button Grid.Column="4" Grid.Row="0" 
                    
Command="igWindows:TabControlCommands.SelectPreviousTab" 
                    
CommandTarget="{Binding ElementName=xamTabControl1}">
                Select_PreviousTab
</Button>

            
<Button Grid.Column="1" Grid.Row="1" 
                    
Command="igWindows:TabControlCommands.CloseSelected" 
                    
CommandTarget="{Binding ElementName=xamTabControl1}">
                Close_Selected
</Button>

            
<Button Grid.Column="2" Grid.Row="1" 
                    
Command="igWindows:TabControlCommands.CloseAll" 
                    
CommandTarget="{Binding ElementName=xamTabControl1}">
                Close_All
</Button>

            
<Button Grid.Column="3" Grid.Row="1" 
                    
Command="igWindows:TabControlCommands.ToggleMinimized" 
                    
CommandTarget="{Binding ElementName=xamTabControl1}">
                _ToggleMinimized
</Button>

            
<Button Grid.Column="4" Grid.Row="1" 
                    
Command="igWindows:TabControlCommands.Expand" 
                    
CommandTarget="{Binding ElementName=xamTabControl1}">
                _Expand
</Button>

            
<Button Grid.Column="5" Grid.Row="1" 
                    
Command="igWindows:TabControlCommands.Minimize" 
                    
CommandTarget="{Binding ElementName=xamTabControl1}">
                _Minimize
</Button>

        
</Grid>
    
</Grid>

</Window>
using Infragistics.Windows.Controls;

private void ExecuteCommands()
{

    // This command will select the first selectable tab, ignoring tabs
    // that are not visible or enabled 
    this.xamTabControl1.ExecuteCommand(TabControlCommands.SelectFirstTab);

    // This command will select the next selectable tab, ignoring tabs
    // that are not visible or enabled 
    this.xamTabControl1.ExecuteCommand(TabControlCommands.SelectNextTab);

    // This command will select the previous selectable tab, ignoring tabs
    // that are not visible or enabled 
    this.xamTabControl1.ExecuteCommand(TabControlCommands.SelectPreviousTab);

    // This command will select the last selectable tab, ignoring tabs
    // that are not visible or enabled 
    this.xamTabControl1.ExecuteCommand(TabControlCommands.SelectLastTab);

    // This command will close all tabs, i.e. set their Visibility property 
    // to 'Collapsed'. To unclose the tabs set their Visibility back to 
    // 'Visible' (see code in btnUncloseAllTabs_Click event handler below)
    this.xamTabControl1.ExecuteCommand(TabControlCommands.CloseAll);
    
    // This command will close the selcted tab if he XamTabControl's 
    // 'AllowTabClosing' property is not set and is not overridden
    // via the TabItemEx's 'AllowClosing' property.
    this.xamTabControl1.ExecuteCommand(TabControlCommands.CloseSelected);
    
    // This command will expand a minimized XamTabControl. The command
    // is disabled if the 'IsMinimized' property is false.
    if ( this.xamTabControl1.IsMinimized == true)
        this.xamTabControl1.ExecuteCommand(TabControlCommands.Expand);
    
    // This command will minimize a XamTabControl. The command
    // is disabled if the 'IsMinimized' property is true or the 
    // 'AlowMinimize' property is false.
    if ( this.xamTabControl1.IsMinimized == false &&
         this.xamTabControl1.AllowMinimize == true)
        this.xamTabControl1.ExecuteCommand(TabControlCommands.Minimize);
    
    // This command will toggle the value of the 'IsMinimized' property.
    // The command is disabled if the 'AlowMinimize' property is false.
    if ( this.xamTabControl1.AllowMinimize == true)
        this.xamTabControl1.ExecuteCommand(TabControlCommands.ToggleMinimized);
}


private void btnUncloseAllTabs_Click(object sender, RoutedEventArgs e)
{
    int count = this.xamTabControl1.Items.Count;

    ItemContainerGenerator generator = this.xamTabControl1.ItemContainerGenerator;

    // loop over all the tab items in the XamTabControl and set their
    // Visibility property to 'Visibile' to un-close them.
    for (int i = 0; i < count; i++)
    {
        TabItem tabItem = generator.ContainerFromIndex(i) as TabItem;

        if (tabItem != null)
            tabItem.Visibility = Visibility.Visible;

    }
}
Imports Infragistics.Windows.Controls

    Private Sub ExecuteCommands()

        ' This command will select the first selectable tab, ignoring tabs
        ' that are not visible or enabled 
        Me.XamTabControl1.ExecuteCommand(TabControlCommands.SelectFirstTab)

        ' This command will select the next selectable tab, ignoring tabs
        ' that are not visible or enabled 
        Me.XamTabControl1.ExecuteCommand(TabControlCommands.SelectNextTab)

        ' This command will select the previous selectable tab, ignoring tabs
        ' that are not visible or enabled 
        Me.XamTabControl1.ExecuteCommand(TabControlCommands.SelectPreviousTab)

        ' This command will select the last selectable tab, ignoring tabs
        ' that are not visible or enabled 
        Me.XamTabControl1.ExecuteCommand(TabControlCommands.SelectLastTab)

        ' This command will close all tabs, i.e. set their Visibility property 
        ' to 'Collapsed'. To unclose the tabs set their Visibility back to 
        ' 'Visible' (see code in btnUncloseAllTabs_Click event handler below)
        Me.XamTabControl1.ExecuteCommand(TabControlCommands.CloseAll)

        ' This command will close the selcted tab if he XamTabControl's 
        ' 'AllowTabClosing' property is not set and is not overridden
        ' via the TabItemEx's 'AllowClosing' property.
        Me.XamTabControl1.ExecuteCommand(TabControlCommands.CloseSelected)

        ' This command will expand a minimized XamTabControl. The command
        ' is disabled if the 'IsMinimized' property is false.
        If (Me.XamTabControl1.IsMinimized = True) Then
            Me.XamTabControl1.ExecuteCommand(TabControlCommands.Expand)
        End If


        ' This command will minimize a XamTabControl. The command
        ' is disabled if the 'IsMinimized' property is true or the 
        ' 'AlowMinimize' property is false.
        If (Me.XamTabControl1.IsMinimized = False AndAlso Me.XamTabControl1.AllowMinimize = True) Then
            Me.XamTabControl1.ExecuteCommand(TabControlCommands.Minimize)
        End If

        ' This command will toggle the value of the 'IsMinimized' property.
        ' The command is disabled if the 'AlowMinimize' property is false.
        If (Me.XamTabControl1.AllowMinimize = True) Then
            Me.XamTabControl1.ExecuteCommand(TabControlCommands.ToggleMinimized)
        End If

    End Sub

    Private Sub btnUncloseAllTabs_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim count As Int32 = Me.XamTabControl1.Items.Count
        Dim generator As ItemContainerGenerator = Me.XamTabControl1.ItemContainerGenerator
        Dim tabItem As TabItem

        ' loop over all the tab items in the XamTabControl and set their
        ' Visibility property to 'Visibile' to un-close them.
        For i As Int32 = 0 To count - 1
            tabItem = TryCast(generator.ContainerFromIndex(i), TabItem)

            If Not tabItem Is Nothing Then
                tabItem.Visibility = Visibility.Visible
            End If
        Next

    End Sub
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also