示例#1
0
        /// <summary>
        /// Handle the MenuItem's Click event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ContextMenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mi = sender as MenuItem;

            if (mi == null)
            {
                return;
            }

            int index;
            // get the index of the TabItem from the manuitems Tag property
            bool b = int.TryParse(mi.Tag.ToString(), out index);

            if (b)
            {
                TabItem tabItem = this.Items[index] as TabItem;
                if (tabItem != null)
                {
                    VirtualizingTabPanel itemsHost = Helper.FindVirtualizingTabPanel(this);
                    if (itemsHost != null)
                    {
                        itemsHost.MakeVisible(tabItem, Rect.Empty);
                    }

                    tabItem.Focus();
                }
            }
        }
示例#2
0
        /// <summary>
        /// OnMinMaxChanged callback responds to any of the Min/Max dependancy properties changing
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        private static void OnMinMaxChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TabControl tc = (TabControl)d;

            if (tc.Template == null)
            {
                return;
            }

            VirtualizingTabPanel tp = Helper.FindVirtualizingTabPanel(tc);

            if (tp != null)
            {
                tp.InvalidateMeasure();
            }
        }
示例#3
0
        /// <summary>
        /// Find the Panel for the TabControl
        /// </summary>
        public static VirtualizingTabPanel FindVirtualizingTabPanel(Visual visual)
        {
            try
            {
                if (visual == null)
                {
                    return(null);
                }

                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(visual); i++)
                {
                    Visual child = VisualTreeHelper.GetChild(visual, i) as Visual;

                    if (child != null)
                    {
                        if (child is VirtualizingTabPanel)
                        {
                            object temp = child;
                            return((VirtualizingTabPanel)temp);
                        }

                        VirtualizingTabPanel panel = FindVirtualizingTabPanel(child);
                        if (panel != null)
                        {
                            object temp = panel;
                            return((VirtualizingTabPanel)temp); // return the panel up the call stack
                        }
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "FindViryualizingabPanel()", "Controls\\VMuktiGrid\\Tab\\Helper.cs");
                return(null);
            }
        }
示例#4
0
        protected override void OnPreviewKeyDown(KeyEventArgs e)
        {
            if (Items.Count == 0)
            {
                return;
            }

            TabItem ti = null;

            switch (e.Key)
            {
            case Key.Home:
                ti = this.Items[0] as TabItem;
                break;

            case Key.End:
                ti = this.Items[Items.Count - 1] as TabItem;
                break;

            case Key.Tab:
                if (e.KeyboardDevice.Modifiers == ModifierKeys.Control)
                {
                    int index     = SelectedIndex;
                    int direction = 1;
                    if (e.KeyboardDevice.Modifiers == ModifierKeys.Shift)
                    {
                        direction = -1;
                    }

                    while (true)
                    {
                        index += direction;
                        if (index < 0)
                        {
                            index = Items.Count - 1;
                        }
                        else if (index > Items.Count - 1)
                        {
                            index = 0;
                        }

                        FrameworkElement ui = Items[index] as FrameworkElement;
                        if (ui.Visibility == Visibility.Visible && ui.IsEnabled)
                        {
                            ti = Items[index] as TabItem;
                            break;
                        }
                    }
                }
                break;
            }

            VirtualizingTabPanel panel = Helper.FindVirtualizingTabPanel(this);

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

                e.Handled = ti.Focus();
            }
            if (!e.Handled)
            {
                base.OnPreviewKeyDown(e);
            }
        }
示例#5
0
        /*
         * Protected override methods
         *
         */

        /// <summary>
        /// OnApplyTemplate override
        /// </summary>
        public override void OnApplyTemplate()
        {
            try
            {
                base.OnApplyTemplate();
                this.AllowDrop = true;

                this.Drop      += new DragEventHandler(TabControl_Drop);
                _RowDefinition0 = this.Template.FindName("RowDefinition0", this) as RowDefinition;
                // 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
                    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
                    {
                        VMukti.App.blnIsTwoPanel = false;
                        TabItem item = new TabItem();

                        item.OwnerTabIndex = this.Items.Count;

                        //TextBlock txtBlock = new TextBlock();
                        //txtBlock.Text = "New Tab - " + this.Items.Count.ToString();
                        ctlPgTabHeader objPgTabHeader = new ctlPgTabHeader();
                        // objPgTabHeader.Title = "New Tab - " + this.Items.Count.ToString();
                        objPgTabHeader.Title = "Untiteled";
                        Image imgIcon = new Image();
                        imgIcon.Source = new BitmapImage(new Uri(@"\Skins\Images\VMuktiIcon.ico", UriKind.RelativeOrAbsolute));
                        imgIcon.Height = 16;
                        imgIcon.Width  = 16;

                        //item.Header = txtBlock;
                        item.Header  = objPgTabHeader;
                        item.Icon    = imgIcon;
                        item.Content = new CustomGrid.ctlGrid();

                        //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 (TabItemAdded != null)
                        {
                            TabItemAdded(this, new TabItemEventArgs(item));
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "OnApplyTemplate()", "Controls\\VMuktiGrid\\Tab\\TabControl.cs");
            }
        }