简体   繁体   中英

Using custom fonts without install win8.1 WPF APP

My WPF win APP is using following code and it works alright when font is already installed.

Button infoButton = new Button();
infoButton.Content = new FontIcon
{
    FontFamily = new FontFamily("Segoe MDL2 Assets"),
    Glyph = "",
    Foreground = new SolidColorBrush(Colors.WhiteSmoke)
};

I want to use custom font without installing it on windows. I've included all relevant font files within my solution (build action set as content). How can I use that with above code? I know how to use it in XAML but I'm want to do it in C#.

I have used the below link to use new Font in the WPF application which is not installed in the system - It worked:

< http://www.bizicbojan.com/post/2011/01/19/Embedding-and-Referencing-Fonts-in-your-WPF-application.aspx >

I have used FontFamily in the control as below.

FontFamily="/HPID.KioskUIControls;component/Fonts/#Segoe MDL2 Assets".

The font file is available in Fonts folder for me.

May be this will help you too.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM