/// <summary>
        /// This method draws additional elements into the main display area
        /// </summary>
        /// <param name="dc">Drawing context</param>
        protected override void CustomRender(DrawingContext dc)
        {
            var primaryTitle   = string.Empty;
            var secondaryTitle = string.Empty;

            foreach (UIElement element in Children)
            {
                var elementType = SimpleView.GetUIElementType(element);
                if (elementType == UIElementTypes.Primary)
                {
                    primaryTitle = SimpleView.GetUIElementTitle(element);
                    break;
                }
            }
            foreach (UIElement element in Children)
            {
                var elementType = SimpleView.GetUIElementType(element);
                if (elementType == UIElementTypes.Secondary)
                {
                    secondaryTitle = SimpleView.GetUIElementTitle(element);
                    break;
                }
            }

            var primaryTitleFont               = PrimaryTitleFont;
            var primaryTitleFontSize           = PrimaryTitleFontSize;
            var primaryTitleBrush1             = PrimaryTitleHeaderBrush;
            var primaryTitleBrush2             = PrimaryTitleFooterBrush;
            var primaryHeaderBackgroundBrush   = PrimaryAreaHeaderBackgroundBrush;
            var secondaryTitleFont             = SecondaryTitleFont;
            var secondaryTitleFontSize         = PrimaryTitleFontSize;
            var secondaryTitleBrush1           = SecondaryTitleHeaderBrush;
            var secondaryTitleBrush2           = SecondaryTitleFooterBrush;
            var secondaryHeaderBackgroundBrush = SecondaryAreaHeaderBackgroundBrush;

            // Calculating the general areas
            var primaryRect = new Rect();

            switch (CalculatedLayout)
            {
            case PrimarySecondaryLayout.PrimaryTopSecondaryBottom:
                primaryRect.Y      = 0d;
                primaryRect.X      = 0d;
                primaryRect.Height = RowDefinitions[0].ActualHeight + RowDefinitions[1].ActualHeight;
                primaryRect.Width  = ActualWidth;
                break;

            case PrimarySecondaryLayout.SecondaryTopPrimaryBottom:
                primaryRect.Y      = RowDefinitions[0].ActualHeight;
                primaryRect.X      = 0d;
                primaryRect.Height = RowDefinitions[1].ActualHeight + RowDefinitions[2].ActualHeight;
                primaryRect.Width  = ActualWidth;
                break;

            case PrimarySecondaryLayout.PrimaryLeftSecondaryRight:
                primaryRect.Y      = 0d;
                primaryRect.X      = 0d;
                primaryRect.Height = ActualHeight;
                primaryRect.Width  = ColumnDefinitions[0].ActualWidth + ColumnDefinitions[1].ActualWidth;
                break;

            case PrimarySecondaryLayout.SecondaryLeftPrimaryRight:
                primaryRect.Y      = 0d;
                primaryRect.X      = ColumnDefinitions[0].ActualWidth;
                primaryRect.Height = ActualHeight;
                primaryRect.Width  = ColumnDefinitions[1].ActualWidth + ColumnDefinitions[2].ActualWidth;
                break;
            }

            var secondaryRect = new Rect();

            switch (CalculatedLayout)
            {
            case PrimarySecondaryLayout.PrimaryTopSecondaryBottom:
                secondaryRect.Y      = RowDefinitions[0].ActualHeight + RowDefinitions[1].ActualHeight;
                secondaryRect.X      = 0d;
                secondaryRect.Height = RowDefinitions[2].ActualHeight;
                secondaryRect.Width  = ActualWidth;
                break;

            case PrimarySecondaryLayout.SecondaryTopPrimaryBottom:
                secondaryRect.Y      = 0d;
                secondaryRect.X      = 0d;
                secondaryRect.Height = RowDefinitions[0].ActualHeight;
                secondaryRect.Width  = ActualWidth;
                break;

            case PrimarySecondaryLayout.PrimaryLeftSecondaryRight:
                secondaryRect.Y      = 0d;
                secondaryRect.X      = ColumnDefinitions[0].ActualWidth + ColumnDefinitions[1].ActualWidth;
                secondaryRect.Height = ActualHeight;
                secondaryRect.Width  = ColumnDefinitions[2].ActualWidth;
                break;

            case PrimarySecondaryLayout.SecondaryLeftPrimaryRight:
                secondaryRect.Y      = 0d;
                secondaryRect.X      = 0d;
                secondaryRect.Height = ActualHeight;
                secondaryRect.Width  = ColumnDefinitions[0].ActualWidth;
                break;
            }

            if (!string.IsNullOrEmpty(primaryTitle))
            {
                var primaryFormattedText1 = new FormattedText(primaryTitle, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(primaryTitleFont, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), primaryTitleFontSize, primaryTitleBrush1)
                {
                    MaxTextWidth = secondaryRect.Width - 4, Trimming = TextTrimming.CharacterEllipsis
                };
                var primaryFormattedText2 = new FormattedText(primaryTitle, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(primaryTitleFont, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), primaryTitleFontSize, primaryTitleBrush2)
                {
                    MaxTextWidth = secondaryRect.Width - 4, Trimming = TextTrimming.CharacterEllipsis
                };

                var headerRect = new Rect(primaryRect.X + 2, primaryRect.Y + 2, primaryRect.Width - 4, primaryFormattedText1.Height + 4);
                dc.DrawRectangle(primaryHeaderBackgroundBrush, null, headerRect);
                dc.DrawText(primaryFormattedText1, new Point(primaryRect.X + 4, primaryRect.Y + 3));

                var mainAreaRect = new Rect(primaryRect.X + 2, primaryRect.Y + headerRect.Height + 4, primaryRect.Width - 4, primaryRect.Height - 2 - headerRect.Height - primaryFormattedText2.Height - 4);
                dc.DrawRectangle(PrimaryAreaBackgroundBrush, null, mainAreaRect);

                var tabRect = new Rect(primaryRect.X + 2, primaryRect.Y + primaryRect.Height - primaryFormattedText2.Height - 4, Math.Min(primaryRect.Width, primaryFormattedText2.Width + 10), primaryFormattedText2.Height + 4);
                dc.DrawRectangle(PrimaryAreaBackgroundBrush, null, tabRect);
                dc.DrawText(primaryFormattedText2, new Point(tabRect.X + 4, tabRect.Y + 2));
            }
            else if (PrimaryAreaBackgroundBrush != null)
            {
                dc.DrawRectangle(PrimaryAreaBackgroundBrush, null, primaryRect);
            }

            if (!string.IsNullOrEmpty(secondaryTitle))
            {
                var secondaryFormattedText1 = new FormattedText(secondaryTitle, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(secondaryTitleFont, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), secondaryTitleFontSize, secondaryTitleBrush1)
                {
                    MaxTextWidth = secondaryRect.Width - 4, Trimming = TextTrimming.CharacterEllipsis
                };
                var secondaryFormattedText2 = new FormattedText(secondaryTitle, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(secondaryTitleFont, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), secondaryTitleFontSize, secondaryTitleBrush2)
                {
                    MaxTextWidth = secondaryRect.Width - 4, Trimming = TextTrimming.CharacterEllipsis
                };

                var headerRect = new Rect(secondaryRect.X + 2, secondaryRect.Y + 2, secondaryRect.Width - 4, secondaryFormattedText1.Height + 4);
                dc.DrawRectangle(secondaryHeaderBackgroundBrush, null, headerRect);
                dc.DrawText(secondaryFormattedText1, new Point(secondaryRect.X + 4, secondaryRect.Y + 3));

                var mainAreaRect = new Rect(secondaryRect.X + 2, secondaryRect.Y + headerRect.Height + 4, secondaryRect.Width - 4, secondaryRect.Height - 2 - headerRect.Height - secondaryFormattedText2.Height - 4);
                dc.DrawRectangle(SecondaryAreaBackgroundBrush, null, mainAreaRect);

                var tabRect = new Rect(secondaryRect.X + 2, secondaryRect.Y + secondaryRect.Height - secondaryFormattedText2.Height - 4, Math.Min(secondaryRect.Width, secondaryFormattedText2.Width + 10), secondaryFormattedText2.Height + 4);
                dc.DrawRectangle(SecondaryAreaBackgroundBrush, null, tabRect);
                dc.DrawText(secondaryFormattedText2, new Point(tabRect.X + 4, tabRect.Y + 2));
            }
            else if (SecondaryAreaBackgroundBrush != null)
            {
                dc.DrawRectangle(SecondaryAreaBackgroundBrush, null, secondaryRect);
            }
        }
Example #2
0
        private void CreateScrollbars()
        {
            if (Parent != null && !(Parent is AdornerDecorator) && (Parent is Grid || Parent is SimpleView || Parent is ContentControl))
            {
                // We need to make sure this control is directly within an adorner decorator
                // so elements in the adorner layer (scroll bars) behave correctly in the Z-Order
                var decorator = new AdornerDecorator
                {
                    VerticalAlignment   = VerticalAlignment,
                    HorizontalAlignment = HorizontalAlignment,
                    Margin = new Thickness(Margin.Left, Margin.Top, Margin.Right, Margin.Bottom),
                    Width  = Width,
                    Height = Height
                };

                Grid.SetColumn(decorator, Grid.GetColumn(this));
                Grid.SetRow(decorator, Grid.GetRow(this));
                Grid.SetColumnSpan(decorator, Grid.GetColumnSpan(this));
                Grid.SetRowSpan(decorator, Grid.GetRowSpan(this));

                SimpleView.SetUIElementTitle(decorator, SimpleView.GetUIElementTitle(this));
                SimpleView.SetUIElementType(decorator, SimpleView.GetUIElementType(this));

                Margin              = new Thickness(0d);
                VerticalAlignment   = VerticalAlignment.Stretch;
                HorizontalAlignment = HorizontalAlignment.Stretch;

                var parentPanel = Parent as Panel;
                if (parentPanel != null)
                {
                    var childItemIndex = -1;
                    var found          = false;
                    foreach (var child in parentPanel.Children)
                    {
                        childItemIndex++;
                        if (child == this)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        parentPanel.Children.Remove(this);
                        parentPanel.Children.Insert(childItemIndex, decorator);
                        decorator.Child = this;
                    }
                }
                else
                {
                    var parentContent = Parent as ContentControl;
                    if (parentContent != null)
                    {
                        parentContent.Content = null;
                        parentContent.Content = decorator;
                        decorator.Child       = this;
                    }
                }
            }

            if (_scrollbarsCreated)
            {
                return;
            }
            _adorner = AdornerLayer.GetAdornerLayer(this);
            if (_adorner == null)
            {
                return;
            }
            _adorner.Add(new BidirectionalStackPanelScrollAdorner(this, _scrollHorizontal, _scrollVertical)
            {
                Visibility = Visibility.Visible
            });
            _scrollHorizontal.ValueChanged += (s, e) => Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(DispatchInvalidateScroll));
            _scrollVertical.ValueChanged   += (s, e) => Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(DispatchInvalidateScroll));
            _scrollbarsCreated              = true;
        }