Maui for android change font size issue

Haviv Elbsz 2,071 Reputation points
2023-12-23T18:27:50.81+00:00

Hello all.

Maui net 8 17.9 preview 2 android emulator 34

in my app I have a variable named fontSize I checked in debugging that

its value changed correctly as expected but in the following its setting not

working. Please can someone give a hint about this behavior?

The text is not change to the value of fontSize. How I can fix that.

Thank you.

    private void HGL_CheckedChanged(object sender, CheckedChangedEventArgs e)
    {
 
      OutputTextRichTextBox.FontSize = fontSize;

      if(HGL.IsChecked == true)
      {
        OutputBackup = OutputTextRichTextBox.Text;
        OutputTextRichTextBox.Text = help_str;
      }
      else 
      {
        OutputTextRichTextBox.Text = OutputBackup;
      }

    }

    <label:MyLabel x:Name="OutputTextRichTextBox"
           FontSize="14"
           TextColor="Black"
           FontAttributes="Bold"
           MinimumWidthRequest="-1" >
    </label:MyLabel>

Developer technologies .NET .NET MAUI
{count} votes

Accepted answer
  1. Anonymous
    2023-12-25T07:57:51.49+00:00

    Hello,

    I can reproduce it, if you set FormattedString for your Label, when you get the value from the Label, you cannot get the text by OutputTextRichTextBox.Text; and it will return null value.

    Then I create a new FormattedString OutputBackupformatted = new FormattedString();

    When you use it in HGL_CheckedChanged, you can get FormattedText by OutputBackupformatted =OutputTextRichTextBox.FormattedText and set it by OutputTextRichTextBox.FormattedText = OutputBackupformatted;.

      private void HGL_CheckedChanged(object sender, CheckedChangedEventArgs e)
       {
    
    
          if (HGL.IsChecked == true)
           {
               OutputBackupformatted = OutputTextRichTextBox.FormattedText;
               OutputTextRichTextBox.FormattedText = HelpStrformatted;
               OutputTextRichTextBox.FontSize = fontSize;
    
              brdrInput.IsVisible = false;
               mainGrid.RowDefinitions[4].Height = new GridLength(0.5, GridUnitType.Star);
               mainGrid.RowDefinitions[6].Height = new GridLength(0, GridUnitType.Star);
               mainGrid.RowDefinitions[7].Height = new GridLength(0);
          }
           else
           {
             
               OutputTextRichTextBox.FormattedText = OutputBackupformatted;
               brdrinput.isvisible = true;
               maingrid.rowdefinitions[4].height = new gridlength(1, gridunittype.star);
               maingrid.rowdefinitions[6].height = new gridlength(1, gridunittype.star);
               maingrid.rowdefinitions[7].height = new gridlength(2);
           }
    
    
          OutputTextRichTextBox.FontSize = fontSize;
    
    
      }
    

    Best Regards,

    Leon Lu


    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.

    0 comments No comments

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.