[Silverlight 技巧探讨1]用Silverlight简单实现多TabItem关闭效果

<UserControl x:Class="SL.Demo1.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">



    <Grid x:Name="LayoutRoot" Background="White">

        <sdk:TabControl x:Name="Tab" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">

            <sdk:TabItem Width="80" Name="TabItem_page1">

                <sdk:TabItem.Header>

                    <StackPanel Orientation="Horizontal">

                        <TextBlock Text="One" VerticalAlignment="Center"></TextBlock>

                        <Button Content="X" Name="btn1" Margin="20,0,0,0" Width="20" Click="btn1_Click"/>

                    </StackPanel>

                </sdk:TabItem.Header>

                This is first page

            </sdk:TabItem>

            <sdk:TabItem Width="80" Name="TabItem_page2">

                <sdk:TabItem.Header>

                    <StackPanel Orientation="Horizontal">

                        <TextBlock Text="Two" VerticalAlignment="Center"></TextBlock>

                        <Button Content="X" x:Name="btn2" Margin="20,0,0,0" Width="20" Click="btn2_Click"/>

                    </StackPanel>

                </sdk:TabItem.Header>

                This is second page

            </sdk:TabItem>

        </sdk:TabControl>

    </Grid>

</UserControl>

 后台托管代码:

using System.Windows;

using System.Windows.Controls;



namespace SL.Demo1
{
public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void btn1_Click(object sender, RoutedEventArgs e) { Tab.Items.Remove(TabItem_page1); } private void btn2_Click(object sender, RoutedEventArgs e) { Tab.Items.Remove(TabItem_page2); } } }

最终的效果如下:

[Silverlight 技巧探讨1]用Silverlight简单实现多TabItem关闭效果

 

你可能感兴趣的:(silverlight)