Exemplo n.º 1
0
        internal bool SelectTabItem(TabItem ti)
        {
            var panel = Helper.FindVirtualizingTabPanel(this);

            if (panel != null)
            {
                panel.MakeVisible(ti, Rect.Empty);
            }

            SelectedItem = ti;

            var result = ti.Focus();

            if (TabItemSelected != null)
            {
                TabItemSelected(this, new TabItemEventArgs(ti));
            }

            return(result);
        }
Exemplo n.º 2
0
        /*
         * Protected override methods
         *
         */

        /// <summary>
        /// OnApplyTemplate override
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // set up the event handler for the template parts
            _toggleButton = this.Template.FindName("PART_DropDown", this) as ToggleButton;
            if (_toggleButton != null)
            {
                // create a context menu for the togglebutton
                System.Windows.Controls.ContextMenu cm = new ContextMenu();
                cm.PlacementTarget = _toggleButton;
                cm.Placement       = PlacementMode.Bottom;

                // create a binding between the togglebutton's IsChecked Property
                // and the Context Menu's IsOpen Property
                Binding b = new Binding();
                b.Source = _toggleButton;
                b.Mode   = BindingMode.TwoWay;
                b.Path   = new PropertyPath(ToggleButton.IsCheckedProperty);

                cm.SetBinding(ContextMenu.IsOpenProperty, b);

                _toggleButton.ContextMenu = cm;
                _toggleButton.Checked    += DropdownButton_Checked;
            }

            ScrollViewer scrollViewer = this.Template.FindName("PART_ScrollViewer", this) as ScrollViewer;

            // set up event handlers for the RepeatButtons Click event
            RepeatButton repeatLeft = this.Template.FindName("PART_RepeatLeft", this) as RepeatButton;

            if (repeatLeft != null)
            {
                repeatLeft.Click += delegate
                {
                    if (scrollViewer != null)
                    {
                        scrollViewer.LineLeft();
                    }

                    GC.Collect();
                };
            }

            RepeatButton repeatRight = this.Template.FindName("PART_RepeatRight", this) as RepeatButton;

            if (repeatRight != null)
            {
                repeatRight.Click += delegate
                {
                    if (scrollViewer != null)
                    {
                        scrollViewer.LineRight();
                    }

                    GC.Collect();
                };
            }

            // set up the event handler for the 'New Tab' Button Click event
            ButtonBase button = this.Template.FindName("PART_NewTabButton", this) as ButtonBase;

            if (button != null)
            {
                button.Click += delegate
                {
                    int i = this.SelectedIndex;

                    TabItem item = new TabItem();
                    item.Header = "New Tab";

                    if (i == -1 || i == this.Items.Count - 1 || AddNewTabToEnd)
                    {
                        this.Items.Add(item);
                    }
                    else
                    {
                        this.Items.Insert(++i, item);
                    }

                    if (SelectNewTabOnCreate)
                    {
                        SelectedItem = item;

                        VirtualizingTabPanel itemsHost = Helper.FindVirtualizingTabPanel(this);
                        if (itemsHost != null)
                        {
                            itemsHost.MakeVisible(item, Rect.Empty);
                        }

                        item.Focus();

                        if (TabItemSelected != null)
                        {
                            TabItemSelected(this, new TabItemEventArgs(item));
                        }
                    }

                    if (TabItemAdded != null)
                    {
                        TabItemAdded(this, new TabItemEventArgs(item));
                    }
                };
            }
        }