2016-11-29 62 views
0

我的WPF win APP使用下面的代碼,當字體已經安裝時,它可以正常工作。使用自定義字體而無需安裝win8.1 WPF APP

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

我想使用自定義字體,而無需在Windows上安裝它。我在解決方案中包含了所有相關的字體文件(將構建操作設置爲內容)。我如何使用上面的代碼?我知道如何在XAML中使用它,但我想在C#中使用它。

+0

你不能將它添加到資源,並從那裏設置字體? – Prajwal

+0

我必須從服務器代碼 – afr0

回答

0

我已經使用了下面的鏈接,其中沒有安裝在系統中的WPF應用程序中使用新的字體 - 它的工作:

< http://www.bizicbojan.com/post/2011/01/19/Embedding-and-Referencing-Fonts-in-your-WPF-application.aspx我在下面的控制中所使用的FontFamily>

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

字體文件在我的字體文件夾中可用。

可能這也會幫助你。

謝謝。

+0

這是再次基於XAML – afr0

+0

是的,這是來自XAML。可能是這個幫助。我沒有嘗試過。 – user2842005

+0

http://www.alteridem.net/2014/02/24/custom-fonts-in-wpf-applications/ ---嘗試此鏈接。 – user2842005