On CurrentPagechange Event of TabbedPage custom Font is not applied on title of last but one Child Page click item

Faiz Quraishi 165 Reputation points
2024-08-19T16:10:22.2133333+00:00

I have TabbedPage in MAUI 8 and API level 34 .

I have multiple tabs loading 3 on each Tab change event,

1-I have applied Font to each child Tab as mentioned https://learn.microsoft.com/en-us/answers/questions/1867067/how-to-set-fontfamily-of-title-of-each-child-of-ne

2- When CurrentPagechange Event of TabbedPage fired i was loosing font for next loaded tab

and its fixed by help mentioned here https://learn.microsoft.com/en-us/answers/questions/1879004/on-currentpagechange-event-of-tabbedpage-custom-fo

Current Issue: On going on Next tab changed by CurrentPagechange Event fonts are fine and attached to title but when I reach to last Tab and return back to last but one i am loosing font but for next back till last tab fonts are attached and working fine.

I have tried with different technique to attach while back to last but one Tab but its not working.

Will some one help in this regards.

WorkingTitleFontTillLast

Not working

NotWorkingFont

I am attaching below custom function on page load

CurrentPageChanged += OnCurrentPageChanged1;

int _TotalTabCount=getTotaltabCount();

private bool isProcessingPageChange = false;

private async void OnCurrentPageChanged1(object sender, EventArgs e)

{

// Prevent multiple triggers

if (isProcessingPageChange) return;

try

{

    this.CurrentPageChanged -= OnCurrentPageChanged1;

    var tabbedPage = (TabbedPage)sender;

    DisplayContent _DisplayContent = (DisplayContent)tabbedPage.SelectedItem;

    if (CurrentPage != null)

    {

        isProcessingPageChange = true;

        

        await Dispatcher.DispatchAsync(async () =>

        {

            await LoadnextThreeTabfromCollectionAndBindToItemSourceoftabbedPae();

            MainThread.BeginInvokeOnMainThread(() =>

            {

                try

                {

                    if (Children.Count > 1)

                    {

                        if (_TotalTabCount != _DisplayContent.CurrentTabNumber)

                        {

                            CurrentPage = Children[1]; // Set the second tab as selected

                        }                                    

                    }

                }

                catch (ArgumentOutOfRangeException ex)

                {

                    

                }

            });

            isProcessingPageChange = false;

        });

    }

}

catch

{

}

finally

{

    isProcessingPageChange = false;

    this.CurrentPageChanged += OnCurrentPageChanged1;

}

}

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

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 42,361 Reputation points Microsoft Vendor
    2024-08-20T03:21:25.3566667+00:00

    Hello,

    After testing, this is caused by the fact that the Handler does not re-execute the method to change the font after reloading the TabbedPageItem.

    You could manually call this.Handler.SetVirtualView(this); method after await LoadnextThreeTabfromCollectionAndBindToItemSourceoftabbedPae(); method to update the fonts directly after loading.

    Best Regards,

    Alec Liu.


    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.

0 additional answers

Sort by: Most helpful

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.