iOS Setting SemanticFocus on ContentPage

Bubba Jones 0 Reputation points
2025-07-24T14:09:57.6266667+00:00

I am testing the voiceover function for iOS. For this I have a ContentPage which contains:

  1. An AccessibilityTitle set to describe the page itself
  2. AccessbilityText for every element within the page (these elements can be Labels, ContentViews etc

What I am trying to achieve is:

A: Upon navigating to the ContentPage should be focused and the AccessibilityTitle should be read.

B: What ACTUALLY occurs is that upon navigating to the ContentPage is that the first element WITHIN the page is automatically gets semantic focus. Thus THAT AccessibilityText is read out (instead of the title of the page).

In order to remedy the above I understand that I have to set the SemanticFocus to the ContentPage itself upon page loading thereby reading out the AccessibilityTitle of the page .

I used the the below in my ContentPageName.xaml.cs to avail. What happens is that the below gets ignored and the first element WITHIN the page automatically gets semantic focus.

    private void OnLoaded(object sender, EventArgs e)
    {
        _ = Task.Run(async () =>
        {            
			// this below is the ContentPage; note that I am waiting for the page to be //fully loaded as per this method
            this.SetSemanticFocus();        
        });
    }
Developer technologies | .NET | .NET MAUI
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Le (WICLOUD CORPORATION) 1,145 Reputation points Microsoft External Staff
    2025-07-25T04:57:18.8366667+00:00

    Hello,

    The method SetSemanticFocus() is being called from a background thread (Task.Run) and possibly before the UI is fully rendered. This prevents the semantic focus from being correctly applied to the ContentPage.

    Recommended Solution:

    I recommend you ensure SetSemanticFocus() is executed on the main UI thread and after the page has appeared. Use the MainThread.BeginInvokeOnMainThread method with a slight delay to allow the layout to complete.

    And in the future, avoid using Task.Run for UI-related operations in .NET MAUI, as it can lead to threading issues.

    Updated Code Example:

    protected override void OnAppearing()
    {
        base.OnAppearing();
       
        MainThread.BeginInvokeOnMainThread(async () =>
        {
            // Allow layout to complete - may need adjustment based on UI complexity
            await Task.Delay(100);
           
            try
            {
                this.SetSemanticFocus();
            }
            catch (Exception ex)
            {
                // Handle potential SetSemanticFocus inconsistencies
                System.Diagnostics.Debug.WriteLine($"SetSemanticFocus failed: {ex.Message}");
            }
        });
    }
    

    I hope this helps resolve the issue.

    Reference:


  2. HARRY FRANK 0 Reputation points
    2025-08-07T08:53:57.6266667+00:00

    This is a well-documented issue with VoiceOver focus behavior on iOS. One tweak that might help is ensuring SetSemanticFocus() runs on the main thread with a slight delay, as VoiceOver often requires the UI to be fully rendered before it respects focus changes. Wrapping the call in Device.BeginInvokeOnMainThread and adding a short Task.Delay (e.g., 100ms) can give the page enough time to settle before setting semantic focus to the ContentPage itself. This has proven effective in similar accessibility scenarios.

    0 comments No comments

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.