Xamarin.Forms でアイコンフォントの導入が簡単になっていた

  • アイコンフォントファイルを入手

github.com

  • Xamarin.Forms 共有プロジェクトにアイコンフォントファイルを追加
    • Fonts フォルダを作って、その下に置くのが無難
  • アイコンフォントファイルのビルドアクションを Embeded Resources にする
  • ExportFontAttribute でフォントファイルを登録する
[assembly: ExportFont("MaterialIcons-Regular.ttf", Alias = "MaterialIcons")]
  • あとは Label や FontImageSource とかで使う
    • Alias は FontFamily の指定に使える
<FontImageSource FontFamily="MaterialIcons"
                 Color="White"
                 Glyph="&#xe5d3;"/>
  • C# での書き方
new FontImageSource
{
    FontFamily = "MaterialIcons",
    Color = Color.White,
    Glyph = char.ConvertFromUtf32(0xe5d3),
};