Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

label font attributes is not working properly. can anyone help me out?

komaramrvkkomaramrvk Member ✭✭

i am creating a label with csharp after that adding label to stackLayout. text and alignments are working fine. but font attribute is not working.

        Label view = new Label
        {
            Text = "Hello",
            FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
            VerticalTextAlignment = TextAlignment.Center,
            HorizontalOptions = LayoutOptions.StartAndExpand,
            HorizontalTextAlignment = TextAlignment.Start,
            LineBreakMode = LineBreakMode.TailTruncation,
            FontAttributes = FontAttributes.Italic
        };

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    What is the version of Xamarin.Forms package on your side ?

    I test on 4.6.0.847 , FontAttributes works as expected .

    Android :

    iOS :

    UWP :

  • komaramrvkkomaramrvk Member ✭✭

    @ColeX hi thanks for the comment. actually i am also getting that in content page. but i am using this in navigationbar. same stacklayout i am passing to NavigationPage.SetTitleView(). so it is showing text in navigationBar. but not working bold italic attributes.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited June 25

    Which platform did you test on ? Could you provide the complete code ?

    I need to reproduce the issue for further troubleshooting .

  • komaramrvkkomaramrvk Member ✭✭
    edited June 25
        public void HandleTabbedPageTitle()
        {
            var page = Navigation.Navigation.NavigationStack.FirstOrDefault(x => x.GetType() == typeof(CustomTabbedPage));
    
            try
            {
                if (Device.RuntimePlatform == Device.Android)
                {
    
                    var p = App.Current.MainPage as CustomNavigationPage;
    
    
                    if (p != null)
                    {
                        p.IsTransparentNav = false;
                        p.BarBackgroundColor = Color.White;
                    }
                }
            }
            catch (Exception ex)
            {
    
            }
            Label view = new Label
            {
                Text = Title,
                VerticalTextAlignment = TextAlignment.Center,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                HorizontalTextAlignment = TextAlignment.Start,
                LineBreakMode = LineBreakMode.TailTruncation,
                FontAttributes= FontAttributes.Bold
            };
            var titleView = new StackLayout
            {
                Children = { view },
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                BackgroundColor = Color.Transparent
            };
    
            CustomNavigationPage.SetTitleView(page, titleView);
        }
    

    this is my actual code. and this for both android and ios

  • ColeXColeX Member, Xamarin Team Xamurai

    It still works .

  • komaramrvkkomaramrvk Member ✭✭

    yeah thanks @ColeX. it is working in sample project. may be that is in my app specific issue. i will find. thanks

  • ColeXColeX Member, Xamarin Team Xamurai
    edited June 26

    If my answer helps , please accept it as answer ,Thanks.

Sign In or Register to comment.