'宣言 Protected Overridable Sub OnClosing( _ ByVal args As TabClosingEventArgs _ )
protected virtual void OnClosing( TabClosingEventArgs args )
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; } }
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