使用
将字体加载到程序中
GetNonCachedFontFamilies(MainPath).FirstOrDefault();
GetNonCachedFontFamilies方法
public static IEnumerable<FontFamily> GetNonCachedFontFamilies(string location) { if (string.IsNullOrEmpty("location")) throw new ArgumentException("Must provide a location", "location"); DirectoryInfo directoryInfo = new DirectoryInfo(location); if (directoryInfo.Exists) { FileInfo[] fileInfos = directoryInfo.GetFiles("*.?tf"); foreach (FileInfo fileInfo in fileInfos) yield return CreateFontFamily(fileInfo.FullName); } else { FileInfo fileInfo = new FileInfo(location); if (fileInfo.Exists) yield return CreateFontFamily(location); } }
CreateFontFamily方法
private static FontFamily CreateFontFamily(string path) { if (!Uri.TryCreate(path, UriKind.Absolute, out Uri uri)) throw new ArgumentException("Must provide a valid location", "path"); return new FontFamily(uri, string.Empty); }
从文件加载字体并使用它创建FontFamily类没有问题。但它必须是手写的西里尔字体,我只能看到像微软Sans Serif这样的东西。 Photo和Font sample file
请在没有xaml的情况下给出答案。我需要以编程方式加载字体。
我在TextBlocks中使用这个字体
最佳答案:
没有答案
联系客服