Articles in this section
Category / Section

How to display custom font in GridCell ?

1 min read

SfDataGrid allows you to display custom fonts in GridCell using GridColumn.RecordFont Property. For that we need to set the GridColumn.LoadUIView property as true.

Follow the below steps in each platform to add the custom font.

Xamarin.Forms.Android:

  • Add your “Font.ttf” file to the Assets folder in your Xamarin.Forms.Android project.

 

  • Right click your font file from the solution explorer and in the properties menu change the BuildAction property of your font file to AndroidAsset and CopyToOutputDirectory as DoNotCopy.

 

Untitled picture.png Machine generated alternative text:
a Advanced 
Build Action 
Copy to Output Directory 
Custom Tool 
Custom Tool Namespace 
AndroidAsset 
Do not copy 
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings

 

Xamarin.Forms.iOS

  • Add your “Font.ttf” file to the Resources folder in your Xamarin.Forms.iOS project.

 

  • Right click your font file from the solution explorer and in the properties menu change the BuildAction property of your font file to BundlerResource and CopyToOutputDirectory as CopyAlways.
  • In addition to this you should edit the Info.PList file of your Xamarin.Forms.iOS project. Refer the info.PList section from the below link to edit the same.
    Link: https://blog.xamarin.com/custom-fonts-in-ios 

 

Untitled picture.png Machine generated alternative text:
E Advanced 
Build Action 
Copy to Output Directory 
Custom Tool 
Custom Tool Namespace 
BundleResource 
Copy always 
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings

 

 

 Xamarin.Forms.UWP:               

  • Add your “Font.ttf” file to the Assets\Fonts folder in your Xamarin.Forms.UWP project.

 

  • Right click your font file from the solution explorer and in the properties menu change the BuildAction property of your font file to Content and CopyToOutputDirectory as DoNotCopy.

 

Untitled picture.png Machine generated alternative text:
g Advanced 
Build Action 
Copy to Output Directory 
Custom Tool 
Custom Tool Namespace 
Content 
Do not copy 
Ink Drawings
Ink Drawings
Ink Drawings
Ink Drawings

 

 

The below code example illustrates how to display custom font in GridCell using RecordFont property.

 
GridTextColumn firstName = new GridTextColumn();
firstName.MappingName = "FirstName";
firstName.LoadUIView = true;
firstName.CellTextSize = 30;
firstName.RecordFont = Device.OnPlatform("Amontillados", "Amontillados.ttf#Amontillados", "Assets/Fonts/Amontillados.ttf#Amontillados");
 

 

Refer the following screenshot that shows the outcome upon execution of the above code.

 

Sample Link:

How to display custom font in GridCell?

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied