private void SetupTextFont(UILabel label, Font font, Color?titleColor)
        {
            if (Element is ContentPage cPage)
            {
                var formattedTitle = CustomPage.GetFormattedTitle(cPage);
                if (formattedTitle != null && formattedTitle.Spans.Count > 0)
                {
                    SetupFormattedText(titleLabel, formattedTitle, cPage.Title);
                }

                var formattedSubtitle = CustomPage.GetFormattedSubtitle(cPage);
                var subtitle          = CustomPage.GetSubtitle(cPage);
                if (formattedSubtitle != null && formattedSubtitle.Spans.Count > 0)
                {
                    subtitleLabel.Hidden = false;
                    SetupFormattedText(subtitleLabel, formattedSubtitle, subtitle);
                }
                else if (!string.IsNullOrWhiteSpace(subtitle))
                {
                    subtitleLabel.Hidden = false;
                    SetupText(subtitleLabel, subtitle, ExtendedNavigationPage.GetSubtitleColor(cPage), ExtendedNavigationPage.GetSubtitleFont(Element));

                    subtitleLabel.SetNeedsDisplay();
                }
            }
            else
            {
                SetupText(label, (Element as Page).Title, titleColor, ExtendedNavigationPage.GetTitleFont(Element));
                subtitleLabel.Text   = string.Empty;
                subtitleLabel.Frame  = CGRect.Empty;
                subtitleLabel.Hidden = true;
            }

            label.SizeToFit();
            subtitleLabel.SizeToFit();
            titleView.SizeToFit();
        }
        private void Element_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var page = sender as Page;

            System.Diagnostics.Debug.WriteLine(e.PropertyName);

            switch (e.PropertyName)
            {
            case Page.TitleProperty.PropertyName:
            case ExtendedNavigationPage.TitleFontProperty.PropertyName:
            case CustomPage.SubtitleProperty.PropertyName:
            case ExtendedNavigationPage.SubtitleFontProperty.PropertyName:
                SetupTextFont(titleLabel, ExtendedNavigationPage.GetTitleFont(page), ExtendedNavigationPage.GetTitleColor(page));

                SetTitlePosition(ExtendedNavigationPage.GetTitlePosition(page), ExtendedNavigationPage.GetTitlePadding(Element), ExtendedNavigationPage.GetTitleMargin(Element), new CGRect(0, 0, Math.Max(subtitleLabel.IntrinsicContentSize.Width, titleLabel.IntrinsicContentSize.Width), (titleLabel.IntrinsicContentSize.Height + subtitleLabel.IntrinsicContentSize.Height + (subtitleLabel.IntrinsicContentSize.Height > 0.0f ? 3.0f : 0.0f))));
                break;

            case ExtendedNavigationPage.TitleColorProperty.PropertyName:
                var titleColor = ExtendedNavigationPage.GetTitleColor(page);
                if (titleColor.HasValue)
                {
                    titleLabel.TextColor = titleColor.Value.ToUIColor();
                }
                break;

            case ExtendedNavigationPage.SubtitleColorProperty.PropertyName:
                var subtitleColor = ExtendedNavigationPage.GetSubtitleColor(page);
                if (subtitleColor.HasValue)
                {
                    subtitleLabel.TextColor = subtitleColor.Value.ToUIColor();
                }
                break;

            case ExtendedNavigationPage.TitlePositionProperty.PropertyName:
            case ExtendedNavigationPage.TitlePaddingProperty.PropertyName:
            case ExtendedNavigationPage.TitleMarginProperty.PropertyName:
                SetTitlePosition(ExtendedNavigationPage.GetTitlePosition(Element), ExtendedNavigationPage.GetTitlePadding(Element), ExtendedNavigationPage.GetTitleMargin(Element), new CGRect(0, 0, Math.Max(subtitleLabel.IntrinsicContentSize.Width, titleLabel.IntrinsicContentSize.Width), (titleLabel.IntrinsicContentSize.Height + subtitleLabel.IntrinsicContentSize.Height + (subtitleLabel.IntrinsicContentSize.Height > 0.0f ? 3.0f : 0.0f))));
                break;

            case ExtendedNavigationPage.GradientColorsProperty.PropertyName:
            case ExtendedNavigationPage.GradientDirectionProperty.PropertyName:
            case ExtendedNavigationPage.BarBackgroundProperty.PropertyName:
            case ExtendedNavigationPage.BarBackgroundOpacityProperty.PropertyName:
                SetupBackground();
                break;

            case ExtendedNavigationPage.HasShadowProperty.PropertyName:
                SetupShadow(ExtendedNavigationPage.GetHasShadow(page));
                break;

            case ExtendedNavigationPage.TitleBackgroundProperty.PropertyName:
                if (!string.IsNullOrEmpty(ExtendedNavigationPage.GetTitleBackground(Element)))
                {
                    titleView.BackgroundColor = UIColor.FromPatternImage(UIImage.FromBundle(ExtendedNavigationPage.GetTitleBackground(Element)));
                }
                else
                {
                    titleView.BackgroundColor = null;
                }
                break;

            case nameof(ExtendedNavigationPage.TitleBorderWidth):
                titleView.Layer.BorderWidth = ExtendedNavigationPage.GetTitleBorderWidth(Element);
                break;

            case nameof(ExtendedNavigationPage.TitleBorderCornerRadius):
                titleView.Layer.CornerRadius = ExtendedNavigationPage.GetTitleBorderCornerRadius(Element);
                break;

            case nameof(ExtendedNavigationPage.TitleBorderColor):
                titleView.Layer.BorderColor = ExtendedNavigationPage.GetTitleBorderColor(Element)?.ToCGColor() ?? UIColor.Clear.CGColor;
                break;

            case nameof(ExtendedNavigationPage.TitleFillColor):
                titleView.BackgroundColor = ExtendedNavigationPage.GetTitleFillColor(Element)?.ToUIColor() ?? UIColor.Clear;
                break;

            case nameof(CustomPage.FormattedTitle):
                if (page is ContentPage cPage)
                {
                    SetupFormattedText(titleLabel, CustomPage.GetFormattedTitle(cPage), cPage.Title);
                }
                break;
            }
        }