How to: Allow Hiding only the Selected Tab Items

  • 3 minutes to read

The following example shows how to allow end-users to only hide selected tab items.In this example, the SelectionChanged event is handled for this purpose. Tab items are obtained using the GetTabItem method.

View Example

<Window xmlns:controls="clr-namespace:DevExpress.Xpf.Core;assembly=DevExpress.Xpf.Core.v10.1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        x:Class="DXTabControl_AllowHideSelectedItem.MainWindow"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid x:Name="LayoutRoot" Loaded="LayoutRoot_Loaded">
        <controls:DXTabControl x:Name="tabControl" Height="150" Width="300"
                       SelectionChanged="tabControl_SelectionChanged">
            <controls:DXTabControl.ItemHeaderTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Path=ProductName}"/>
                </DataTemplate>
            </controls:DXTabControl.ItemHeaderTemplate>
            <controls:DXTabControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="ID = "/>
                            <TextBlock Text="{Binding Path=ID}" Foreground="Blue"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Price = "/>
                            <TextBlock Text="{Binding Path=Price}" Foreground="Blue"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Discount = "/>
                            <TextBlock Text="{Binding Path=Discount}" Foreground="Blue"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Order Date = "/>
                            <TextBlock Text="{Binding Path=OrderDate}" Foreground="Blue"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Status = "/>
                            <TextBlock Text="{Binding Path=Status}" Foreground="Blue"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Urgent = "/>
                            <TextBlock Text="{Binding Path=IsUrgent}" Foreground="Blue"/>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </controls:DXTabControl.ItemTemplate>
            <controls:DXTabControl.View>
                <controls:TabControlScrollView AllowHideTabItems="False"/>
            </controls:DXTabControl.View>
        </controls:DXTabControl>
    </Grid>
</Window>