0
votes

I'm just going through customizing fonts in Xamarin.Forms. I want to set custom fonts in my entire app. I read many notes, articles, etc, defining about customizing font in Xamarin.Forms, but they shows only how to change fonts to some controls like label, button, etc.

I want to set custom fonts to controls which don't have a font property (eg. Picker).

Is it possible to do it.

How can i customize every fonts used in my App ?

1
As the Xamarin.Forms community know by now, that if it's not defined then your goto answer is custom renderers. Unfortunately, thats all I can provide. On a side note, I would say its not a good idea to change away from the default font. Google/Apple has spent loads of money/time in researching the best font.Johan
@Johan : That's right but in my case, I'm working on a special app which need to stand alone in it's unique design and style as per the nature of that corresponding application, and it also decide the existence of that one in the market. And my client is strict in these terms.Yksh
It's right what @Johan says: Do it via CustomRenderers for all controls that don't allow you to set a custom font directly. But maybe it is better to use Xamarin.Android's and Xamarin.iOS' native UI toolkits because you have not that much restrictions for customization.Wosi

1 Answers

1
votes

On controls that don't have font properties you need to use custom renderers for each platform. Unfortunately no other way unless Xamarin Forms exposes the property.

For the picker on WinPhone for example, in the CustomRenderer

  protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            switch (e.PropertyName)
            {
                case "Renderer":

                    ((ListPicker)((System.Windows.Controls.Grid)this.Control).Children[0]).FullModeItemTemplate = (System.Windows.DataTemplate)App.Current.Resources["PickerItemTemplate"];
                    ((ListPicker)((System.Windows.Controls.Grid)this.Control).Children[0]).FullModeItemTemplate = (System.Windows.DataTemplate)App.Current.Resources["ListItemTemplate"];

                    break;
            }
        }

With these two resources

    <DataTemplate x:Key="PickerItemTemplate">
        <StackPanel MinWidth="1000">
            <TextBlock Text="{Binding Data}" Opacity="{Binding Opacity}" />
        </StackPanel>
    </DataTemplate>
    <DataTemplate x:Key="ListItemTemplate">
        <StackPanel Margin="0,15,0,15">
            <TextBlock Text="{Binding Data}" FontSize="22" TextWrapping="Wrap"></TextBlock>
        </StackPanel>
    </DataTemplate>