Category / Section
How to display custom font in GridCell ?
5 mins 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.
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
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.
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?