wpf TabControl控件的用法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace wpf控件互相绑定
{
    /// <summary>
    /// Window2.xaml 的交互逻辑
    /// </summary>
    public partial class Window2 : Window
    {
        public Window2()
        {
            InitializeComponent();
        }
        //当点击打开的时候
        int i = 0;
        TabItem tab;
        TextBox tb;
        DataGrid dg;
      
        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
           tab=new TabItem();  //造选项卡
           tab.Header = "新窗口" + (i+1);  //新选项卡的名字
           TabControl1.Items.Add(tab);  //选项卡集合

           TabControl1.SelectedIndex = i;

           tb = new TextBox();
           tb.Width = 200;
           tb.Height = 200;
        

           if (i==0)
           {
                 tab.Content = tb;
           }

           tab.MouseDoubleClick += tab_MouseDoubleClick;//双击关闭选项卡

           i++;  

        }

        private void tab_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TabItem s = (TabItem)sender;
            TabControl1.Items.Remove(s);
        }

 

posted @ 2015-07-01 13:52  zhenximeiyitian  阅读(2067)  评论(0编辑  收藏  举报