Пример #1
0
        /// <summary>
        /// Called when the button is clicked
        /// </summary>
        protected override void OnClick()
        {
            if (TabControl == null)
            {
                return;
            }

            var menu    = new ContextMenu();
            var counter = -1;

            foreach (var view in Shell.Current.NormalViews)
            {
                counter++;
                var menuItem = new SelectViewMenuItem(TabControl, counter);
                menuItem.Header = SimpleView.GetTitle(view.View);
                var viewColor = SimpleView.GetViewThemeColor(view.View);
                if (viewColor.A == 0)
                {
                    var viewColorResource = FindResource("CODE.Framework-Application-ThemeColor1");
                    if (viewColorResource != null)
                    {
                        viewColor = (Color)viewColorResource;
                    }
                }
                if (viewColor.A != 0)
                {
                    menuItem.Background = new SolidColorBrush(viewColor);
                }
                menu.Items.Add(menuItem);
            }
            menu.Placement        = PlacementMode.Bottom;
            menu.HorizontalOffset = ActualWidth;
            menu.PlacementTarget  = this;
            menu.IsOpen           = true;
        }
Пример #2
0
        /// <summary>
        /// Draws the content of a <see cref="T:System.Windows.Media.DrawingContext" /> object during the render pass of a <see cref="T:System.Windows.Controls.Panel" /> element.
        /// </summary>
        /// <param name="dc">The <see cref="T:System.Windows.Media.DrawingContext" /> object to draw.</param>
        protected override void OnRender(DrawingContext dc)
        {
            base.OnRender(dc);

            var children = GetCurrentChildren();

            if (children.Count < 1)
            {
                return;
            }

            _hitZones.Clear();
            var headerHeight = GetHeaderHeight() + 5;
            var currentLeft  = HorizontalHeaderRenderingOffset;
            var index        = SelectedIndex; // Our "first" element is the element that is selected again
            var isFirst      = true;

            foreach (var child in children)
            {
                var title = SimpleView.GetTitle(child.Child);
                if (string.IsNullOrEmpty(title))
                {
                    title = "Item";
                }
                var ft = isFirst ? new FormattedText(title, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(HeaderFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), HeaderFontSize, SelectedHeaderForeground) : new FormattedText(title, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(HeaderFontFamily, FontStyles.Normal, FontWeights.Light, FontStretches.Normal), HeaderFontSize, UnselectedHeaderForeground);
                dc.DrawText(ft, new Point(currentLeft, 0d));

                if (index > Children.Count - 1)
                {
                    index = 0;                             // We wrap back to item 0 when we shoot out the back
                }
                _hitZones.Add(new PanoramaHeaderHitZone {
                    Index = child.ActualChildIndex, Rect = GeometryHelper.NewRect(currentLeft - 10, 0d, ft.Width + 15, headerHeight)
                });

                currentLeft += ft.Width + 25;
                index++;
                isFirst = false;
            }
        }
Пример #3
0
        /// <summary>
        /// Returns a list of grouped views.
        /// </summary>
        /// <param name="views">The views.</param>
        /// <returns>Dictionary&lt;System.String, List&lt;ViewResult&gt;&gt;.</returns>
        private Dictionary <string, List <ViewResult> > GetGroupedViews(IEnumerable <ViewResult> views)
        {
            var groups = new Dictionary <string, List <ViewResult> >();

            foreach (var view in views.Where(v => v.View != null))
            {
                var group = SimpleView.GetGroup(view.View).Trim();
                if (string.IsNullOrEmpty(group) && !CombineAllEmptyGroups)
                {
                    group = SimpleView.GetTitle(view.View);
                }
                if (!groups.ContainsKey(group))
                {
                    groups.Add(group, new List <ViewResult> {
                        view
                    });
                }
                else
                {
                    groups[group].Add(view);
                }
            }
            return(groups);
        }
Пример #4
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;
                }
            }
        }