バージョン

Closing イベント (TabItemEx)

TabItem が閉じられようとしているときに発生します (キャンセル可能)
シンタックス
'宣言
 
Public Event Closing As EventHandler(Of TabClosingEventArgs)
public event EventHandler<TabClosingEventArgs> Closing
イベント データ

イベント ハンドラが、このイベントに関連するデータを含む、TabClosingEventArgs 型の引数を受け取りました。次の TabClosingEventArgs プロパティには、このイベントの固有の情報が記載されます。

プロパティ解説
Cancel Infragistics.Windows.Controls.Events.CancelableRoutedEventArgsから継承されます。関連する操作がキャンセルされるかどうかを示すブール値を取得または設定します。
Handled System.Windows.RoutedEventArgsから継承されます。Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.
OriginalSource System.Windows.RoutedEventArgsから継承されます。Gets the original reporting source as determined by pure hit testing, before any possible System.Windows.RoutedEventArgs.Source adjustment by a parent class.
RoutedEvent System.Windows.RoutedEventArgsから継承されます。Gets or sets the System.Windows.RoutedEventArgs.RoutedEvent associated with this System.Windows.RoutedEventArgs instance.
Source System.Windows.RoutedEventArgsから継承されます。Gets or sets a reference to the object that raised the event.
使用例
public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();

        // Allow tab closing by default.
        this.xamTabControl1.AllowTabClosing = true;
        
        // Note: tab closing can be overriden on each TabItemEx by setting its AllowClosing
        // property, e.g.
        ((TabItemEx)this.xamTabControl1.Items[0]).AllowClosing = false;

        // Show a close button in the tab header area that will close the selected tab
        this.xamTabControl1.ShowTabHeaderCloseButton = true;

        // Show a close button in the TabItemEx if the tab is selected
        // or if the mouse is over it.
        this.xamTabControl1.TabItemCloseButtonVisibility = TabItemCloseButtonVisibility.WhenSelectedOrHotTracked;
        
        // Note: tab item close button visibility can be overriden on each TabItemEx by 
        // setting its CloseButtonVisibility property, e.g.
        ((TabItemEx)this.xamTabControl1.Items[2]).CloseButtonVisibility = TabItemCloseButtonVisibility.Hidden;

        // Wire the Closing event for a specific tab. Setting Cancel to true inside the event will 
        // prevent the tab from being closed
        ((TabItemEx)this.xamTabControl1.Items[1]).Closing += new EventHandler<TabClosingEventArgs>(tabItemEx2_Closing);

        // Note: when the XamTabControl closes a tab it leaves it in the Items
        // collection and just sets the tab item's Visibility to 'Collapsed'.
        // Therefore, to unclose a tab set its Visibility property back to 'Visible'
        // (see the btnUncloseAllTabs_Click event handler below).
    }

    private void tabItemEx2_Closing(object sender, TabClosingEventArgs e)
    {
        // Setting Cancel to true will prevent the tab from being closed
        e.Cancel = true;
    }

    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;

        }
    }
<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="300" Width="647" 
    
xmlns:igThemes="http://infragistics.com/Themes" 
    
xmlns:igWindows="http://infragistics.com/Windows">
    
<Grid >
        
<igWindows:XamTabControl Name="xamTabControl1" 
             
Margin="19,50,10,12"
             
AllowTabClosing="True"
             
ShowTabHeaderCloseButton="True"
             
TabItemCloseButtonVisibility="WhenSelectedOrHotTracked">

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

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

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

        
</igWindows:XamTabControl>

        
<Button Name="btnUncloseAllTabs" Height="32" HorizontalAlignment="Left" Margin="300,12,0,0" VerticalAlignment="Top" Width="150" 
                    
Click="btnUncloseAllTabs_Click">Unclose all tabs</Button>
    
</Grid>
</Window>
Imports Infragistics.Windows.Controls
Imports Infragistics.Windows.Controls.Events
Imports System.Windows.Controls.Primitives
Imports System.Diagnostics
Imports System.Windows

Class Window1

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        ' Allow tab closing by default.
        Me.XamTabControl1.AllowTabClosing = True

        ' Note: tab closing can be overriden on each TabItemEx by setting its AllowClosing
        ' property, e.g.
        TryCast(Me.XamTabControl1.Items(0), TabItemEx).AllowClosing = False

        ' Show a close button in the tab header area that will close the selected tab
        Me.XamTabControl1.ShowTabHeaderCloseButton = True

        ' Show a close button in the TabItemEx if the tab is selected
        ' or if the mouse is over it.
        Me.XamTabControl1.TabItemCloseButtonVisibility = TabItemCloseButtonVisibility.WhenSelectedOrHotTracked

        ' Note: tab item close button visibility can be overriden on each TabItemEx by 
        ' setting its CloseButtonVisibility property, e.g.
        TryCast(Me.XamTabControl1.Items(2), TabItemEx).CloseButtonVisibility = TabItemCloseButtonVisibility.Hidden

        Dim tab As TabItemEx = TryCast(Me.XamTabControl1.Items(1), TabItemEx)

        ' Wire the Closing event for a specific tab. Setting Cancel to true inside the event will 
        ' prevent the tab from being closed
        AddHandler tab.Closing, AddressOf tabItem_Closing

        ' Note: when the XamTabControl closes a tab it leaves it in the Items
        ' collection and just sets the tab item's Visibility to 'Collapsed'.
        ' Therefore, to unclose a tab set its Visibility property back to 'Visible'
        ' (see the btnUncloseAllTabs_Click event handler below).

    End Sub

    Private Sub tabItem_Closing(ByVal sender As Object, ByVal e As TabClosingEventArgs)
        ' Setting Cancel to true will prevent the tab from being closed
        e.Cancel = True
    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
参照