Beispiel #1
0
        private void ChangeFont(Page page)
        {
            var currentValue = page.GetValue(TitleViewProperty);

            if (currentValue != null)
            {
                return;
            }

            var textAlignment = (TextAlignment)page.GetValue(AppBarTitleTextAlignmentProperty);
            var fontFamily    = (string)page.GetValue(AppBarTitleTextFontFamilyProperty);
            var fontSize      = (double)page.GetValue(AppBarTitleTextFontSizeProperty);

            if (string.IsNullOrEmpty(fontFamily))
            {
                fontFamily = Material.FontFamily.H6;
            }

            _customTitleView = new TitleLabel();

            if (Device.RuntimePlatform == Device.iOS)
            {
                if (this.Navigation.NavigationStack.Count == 1)
                {
                    _customTitleView.Margin = new Thickness(8, 0, 8, 0);
                }
                else
                {
                    _customTitleView.Margin = new Thickness(8, 0, 32, 0);
                }
            }

            if (Device.RuntimePlatform == Device.Android && this.Navigation.NavigationStack.Count > 1 && page.ToolbarItems.Count == 0)
            {
                _customTitleView.Margin = new Thickness(0, 0, 72, 0);
            }

            page.SetValue(TitleViewProperty, _customTitleView);

            _customTitleView.VerticalTextAlignment   = TextAlignment.Center;
            _customTitleView.VerticalOptions         = LayoutOptions.FillAndExpand;
            _customTitleView.HorizontalOptions       = LayoutOptions.FillAndExpand;
            _customTitleView.HorizontalTextAlignment = textAlignment;
            _customTitleView.SetDynamicResource(StyleProperty, "Material.TypeScale.H6");
            _customTitleView.FontFamily = fontFamily;
            _customTitleView.FontSize   = fontSize;
            _customTitleView.Text       = page.Title;
        }