Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper FontFamily setting #407

Open
SKProCH opened this issue Oct 8, 2024 Discussed in #406 · 1 comment
Open

Proper FontFamily setting #407

SKProCH opened this issue Oct 8, 2024 Discussed in #406 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@SKProCH
Copy link
Collaborator

SKProCH commented Oct 8, 2024

Discussed in #406

Originally posted by PRNDA October 7, 2024
Hey everyone,
I want to replace the default font in Material Avalonia globally. I have googled around for a while, but nothing useful has been found.

@SKProCH SKProCH added the bug Something isn't working label Oct 8, 2024
@SKProCH SKProCH self-assigned this Oct 8, 2024
@PRNDA
Copy link

PRNDA commented Oct 9, 2024

The default font is defined as a FontFamily resource name MaterialDesignFonts in Material.Styles/Resources/Themes/FontFamily.axaml.

I tried creating resources with the same name in Application.Resources, but this didn't work.

<Application>
  <Application.Styles>
    <themes:MaterialTheme BaseTheme="Light" PrimaryColor="Green" SecondaryColor="Blue" />
  </Application.Styles>

  <Application.Resources>
    <FontFamily x:Key="MaterialDesignFonts">
      Microsoft Yahei, 微软雅黑,Simsun, SimHei, PingFang SC, 苹方-简, 宋体-简, 宋体, Microsoft JhengHei, Microsoft JhengHei UI, $Default
    </FontFamily>

  </Application.Resources>
</Application>

Screenshot:
image

Finally, I ended up defining several styles applied to TextBlock/TextBox/AccessText, like this:

<Application >
  <Application.Resources>
    <FontFamily x:Key="MaterialDesignFonts">
      Microsoft Yahei, 微软雅黑,Simsun, SimHei, PingFang SC, 苹方-简, 宋体-简, 宋体, Microsoft JhengHei, Microsoft JhengHei UI, $Default
    </FontFamily>
  </Application.Resources>

  <Application.Styles>
    <themes:MaterialTheme BaseTheme="Light" PrimaryColor="Green" SecondaryColor="Blue" />

    <Style Selector="TextBlock">
      <Setter Property="FontFamily" Value="{StaticResource MaterialDesignFonts}" />
    </Style>
    <Style Selector="TextBox">
      <Setter Property="FontFamily" Value="{StaticResource MaterialDesignFonts}" />
    </Style>
    <Style Selector="AccessText">
      <Setter Property="FontFamily" Value="{StaticResource MaterialDesignFonts}" />
    </Style>

  </Application.Styles>

</Application>

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants