Esempio n. 1
0
        /// <summary>
        /// Renders the actual tabs
        /// </summary>
        /// <param name="dc">The dc.</param>
        /// <param name="tabItemsPanel">The tab items panel.</param>
        public void Render(DrawingContext dc, TabItemsPanel tabItemsPanel)
        {
            // Making sure we have a selected page.
            if (tabItemsPanel.SelectedPage < 0)
            {
                var visibleCounter = -1;
                foreach (var element in tabItemsPanel.Children.OfType <UIElement>())
                {
                    visibleCounter++;
                    if (TabItemsPanel.GetTabVisibility(element) == Visibility.Visible)
                    {
                        tabItemsPanel.SelectedPage = visibleCounter;
                        break;
                    }
                }
                return;
            }

            // Making sure the selected page is in fact visible
            var allPages = tabItemsPanel.Children.OfType <UIElement>().ToList();

            if (TabItemsPanel.GetTabVisibility(allPages[tabItemsPanel.SelectedPage]) != Visibility.Visible)
            {
                var visibleCounter = -1;
                foreach (var element in tabItemsPanel.Children.OfType <UIElement>())
                {
                    visibleCounter++;
                    if (TabItemsPanel.GetTabVisibility(element) == Visibility.Visible)
                    {
                        tabItemsPanel.SelectedPage = visibleCounter;
                        break;
                    }
                }
                return;
            }

            _pageHeaders.Clear();
            foreach (var element in tabItemsPanel.Children.OfType <UIElement>())
            {
                var header = SimpleView.GetTitle(element).Trim();
                if (string.IsNullOrEmpty(header))
                {
                    header = "Item";
                }
                _pageHeaders.Add(header);
            }

            _headerRectangles.Clear();

            var boldType    = new Typeface(FontFamily, FontStyles.Normal, FontWeights.Bold, FontStretches.Normal);
            var regularType = new Typeface(new FontFamily("Segoe UI"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);

            var linePen      = new Pen(Brushes.Gray, 1d);
            var highlightPen = new Pen(Brushes.RoyalBlue, 2d);

            dc.DrawLine(linePen, new Point(0, 29.5), new Point(tabItemsPanel.ActualWidth, 29.5));

            var counter = -1;
            var left    = 5d;

            foreach (var element in tabItemsPanel.Children.OfType <UIElement>())
            {
                counter++;

                if (TabItemsPanel.GetTabVisibility(element) != Visibility.Visible)
                {
                    _headerRectangles.Add(Rect.Empty);
                    continue;
                }

                if (counter == tabItemsPanel.SelectedPage)
                {
                    var ft         = new FormattedText(_pageHeaders[counter], CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, boldType, 11d, Brushes.Black);
                    var textWidth  = ft.Width;
                    var headerRect = new Rect(left, 0, textWidth + 20, 30);
                    _headerRectangles.Add(headerRect);
                    dc.DrawRectangle(Brushes.White, null, headerRect);
                    dc.DrawLine(linePen, new Point(left, 3), new Point(left, 30));
                    dc.DrawLine(linePen, new Point(left + textWidth + 20, 3), new Point(left + textWidth + 20, 30));
                    dc.DrawLine(highlightPen, new Point(left, 2), new Point(left + textWidth + 20, 2));
                    dc.DrawText(ft, new Point(left + 10, 7));
                    left += textWidth + 20;
                }
                else
                {
                    var ft         = new FormattedText(_pageHeaders[counter], CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, regularType, 11d, Brushes.Black);
                    var textWidth  = ft.Width;
                    var headerRect = new Rect(left, 0, textWidth + 20, 30);
                    _headerRectangles.Add(headerRect);
                    dc.DrawRectangle(Brushes.Transparent, null, headerRect); // Makes the area hit-test visible
                    dc.DrawText(ft, new Point(left + 10, 7));
                    left += textWidth + 20;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handles a mouse click
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="mouseButtonEventArgs">The <see cref="MouseButtonEventArgs"/> instance containing the event data.</param>
        /// <param name="tabItemsPanel">The tab items panel.</param>
        public void MouseClick(Point position, MouseButtonEventArgs mouseButtonEventArgs, TabItemsPanel tabItemsPanel)
        {
            var counter = -1;

            foreach (var rect in _headerRectangles)
            {
                counter++;
                if (rect.Contains(position))
                {
                    tabItemsPanel.SelectedPage   = counter;
                    mouseButtonEventArgs.Handled = true;
                    return;
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Returns the size and position of the client area for child elements
 /// </summary>
 /// <param name="panel">The tab items panel.</param>
 /// <param name="finalSize">The size of the tab items panel.</param>
 /// <returns>Rect.</returns>
 public Rect GetClientRect(TabItemsPanel panel, Size finalSize)
 {
     return(GeometryHelper.NewRect(2, HeaderHeight + 2, finalSize.Width - 4, finalSize.Height - HeaderHeight - 4));
 }