FontFamily处理对字体文件的引用

时间:2014-05-08 12:05:55

标签: c# wpf

我有Button控件,我想将自定义文件夹中的字体应用到它。 为了做到这一点,我使用System.Windows.Media.FontFamily创建了一个new FontFamily(new Uri(mypath), myfamily)对象,它运行正常。但在某些时刻我想删除我的路径(使用字体文件),我得到访问被拒绝错误。

我尝试使用空构造函数重新创建FontFamily对象,但错误仍然存​​在。这个问题闻起来像.NET bug。

如何卸载FontFamily或从字体文件中删除引用?

示例:

void setFont()
{
    button.FontFamily = new FontFamily(new Uri("file:///d:/MyFonts/"), "./#Pericles Light");
}

void unsetFont()
{
    button.FontFamily = new FontFamily();
}

调用unsetFont()方法后,仍然拒绝MyFonts文件夹。

0 个答案:

没有答案