示例#1
0
        protected override void OnClick()
        {
            base.OnClick();

            if (!string.IsNullOrEmpty(Name) && Name == "PART_Close_TabItem")
            {
                TabItemClose itemclose = FindVisualParent <TabItemClose>(this);

                (itemclose.Parent as TabControl).Items.Remove(itemclose);
                RoutedEventArgs args = new RoutedEventArgs(TabItemClose.CloseItemEvent, itemclose);
                itemclose.RaiseEvent(args);

                WinSet.MainWindow.SetNavNoChecked(itemclose.Header.ToString());
            }
        }
示例#2
0
        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            RadioButton radio = sender as RadioButton;

            SetOtherNavNoChecked(radio);
            var tabName = radio.Content.ToString();


            var isContain = false;

            foreach (TabItem tabItem in this.tabControl.Items)
            {
                if (tabItem.Header.ToString() == tabName)
                {
                    isContain = true;
                }
            }

            if (!isContain)
            {
                if ((this.tabControl.Items.Count + 1) * 100 > this.ActualWidth - 210) /*this.tabControl.Width为NaN*/
                {
                    MessageBox.Show("打开的选项卡过多!");
                    this.SetNavNoChecked(tabName);
                    this.SetOneNavChecked();
                    return;
                }

                var a = new TabItemClose();
                //a.Cursor = Cursors.Hand;
                a.Header = tabName;
                a.Height = 30;
                a.Width  = 100;

                var g = new Grid();
                g.Children.Add(GetTabItem(tabName));

                //g.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFECF0F5"));
                ImageBrush ib = new ImageBrush()
                {
                    ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/Character.jpg", UriKind.RelativeOrAbsolute)), Opacity = 0.1
                };
                g.Background = ib;

                a.Content = g;
                //this.tabControl.Items.Add(a);
                IsChangeNavChecked            = true;
                this.tabControl.SelectedIndex = this.tabControl.Items.Add(a);
                IsChangeNavChecked            = false;
            }
            else
            {
                for (var i = 0; i < this.tabControl.Items.Count; i++)
                {
                    if ((this.tabControl.Items[i] as TabItem).Header.ToString() == tabName)
                    {
                        IsChangeNavChecked            = true;
                        this.tabControl.SelectedIndex = i;
                        IsChangeNavChecked            = false;
                        return;
                    }
                }
            }

            // IsChangeNavChecked = false;
        }