On CurrentPagechange Event of TabbedPage custom Font is not applied on title of each Child Page

Faiz Quraishi 85 Reputation points
2024-08-16T09:48:36.7533333+00:00

I am using TabbedPage and APi level is 34

initially I am loading three Tab on it and on CurrentPageChanged again displaying next three tabs.

As the solution provided on Question https://video2.skills-academy.com/en-us/answers/questions/1867067/how-to-set-fontfamily-of-title-of-each-child-of-ne

its working fine for first load but second load of iteration its loosing fonts.

I have used Dispatcher.DispatchAsync and MainThread.BeginInvokeOnMainThread inside CurrentPageChanged as per my functional requirement.

will some one help on this scenario.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,412 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 30,666 Reputation points Microsoft Vendor
    2024-08-19T05:39:24.4466667+00:00

    Hello,

    Please overwrite the UpdateValue method and add the following code in the handler class:

    public override void UpdateValue(string property)
      {
          base.UpdateValue(property); 
          var tabs = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity?.FindViewById<FragmentContainerView>(Microsoft.Maui.Resource.Id
          .navigationlayout_toptabs); 
          var tabLayout = tabs?.GetChildAt(0); 
          if (tabLayout is TabLayout layout) {
              for (int i = 0; i < layout.TabCount; i++)
              {
                  TabLayout.Tab? tab = layout.GetTabAt(i);
                  TabLayout.TabView? view1 = tab?.View;
     
                  for (int j = 0; j < (view1?.ChildCount ?? 0); j++)
                  {
                      var child = view1?.GetChildAt(j);
     
                      if (child is TextView tv)
                      {
                          tv.Typeface = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.Resources.GetFont(Resource.Raw.alexbrushregular);
                      }
                  }
              }
          }
      }
    

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

9 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.