Responding to Dynamic Text changes at runtime

Joe Manke 1,091 Reputation points
2021-04-15T21:36:11.343+00:00

I'm working on adding some better accessibility support to a Xamarin.Forms application, including font scaling. For test purposes, I have made a new solution with a very simple layout:

<StackLayout Padding="20">
    <Label Text="Small" FontSize="Small"/>
    <Label Text="Medium" FontSize="Medium"/>
    <Label Text="Large" FontSize="Large"/>
    <Label Text="BodyStyle" Style="{DynamicResource BodyStyle}"/>
    <Label Text="Font Size 24" FontSize="24"/>
</StackLayout>

On Android, when I go to Settings, change the font size, and return to the app, all 5 labels change in response to the accessibility settings. On iOS, only the BodyStyle changes unless I swipe-kill and reopen the app. Is there an AppDelegate override or something I can add so I can respond to accessibility changes without killing the app or needing dynamic resources for everything?

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,756 Reputation points
    2021-04-16T07:56:40.253+00:00

    Hello,

    Welcome to Microsoft Q&A!

    You can simply use the following code in iOS project to detect when the accessibility settings has been changed .

       Foundation.NSObject observerToken  
                    = UIApplication.Notifications.ObserveContentSizeCategoryChanged(  
                        (s, e) =>  
                        {   
                               //use messaging center  
                        });  
    

    Then you can send message to forms project to rebuild your UI.

    Refer to https://forums.xamarin.com/discussion/186212/how-to-handle-dynamic-type-the-larger-text-accessibility-option-on-ios-without-re-starting-app#latest .


    If the response is helpful, please click "Accept Answer" and upvote it.
    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.


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.