我想使用c#將可用字體的列表加載到winrt應用程序的組合框中。在.Net中這是簡單的任務,但我無法在winrt中找到相應的API。我該怎麼做?在WINRT中使用c#加載可用字體的列表
0
A
回答
4
您需要使用DirectWrite。有一個片段在這裏做到這一點:
https://github.com/christophwille/winrt-snippets/tree/master/EnumerateFonts
複製粘貼&:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using SharpDX.DirectWrite;
namespace EnumerateFonts
{
public class InstalledFont
{
public string Name { get; set; }
// Code taken straight from SharpDX\Samples\DirectWrite\FontEnumeration\Program.cs
public static List<InstalledFont> GetFonts()
{
var fontList = new List<InstalledFont>();
var factory = new Factory();
var fontCollection = factory.GetSystemFontCollection(false);
var familyCount = fontCollection.FontFamilyCount;
for (int i = 0; i < familyCount; i++)
{
var fontFamily = fontCollection.GetFontFamily(i);
var familyNames = fontFamily.FamilyNames;
int index;
if (!familyNames.FindLocaleName(CultureInfo.CurrentCulture.Name, out index))
familyNames.FindLocaleName("en-us", out index);
string name = familyNames.GetString(index);
fontList.Add(new InstalledFont()
{
Name = name,
});
}
return fontList;
}
}
}
0
還有枚舉字體而不SharpDX的方式。 https://code.msdn.microsoft.com/FontExplorer-lets-you-f01d415e#content
相關問題
- 1. WinRT中使用C#的列表視圖
- 2. 加載後可以使用的C#字體
- 3. gvim中可用的字體列表
- 4. 使用webpack加載字體
- 5. 加載外部字體並在C#中使用它#
- 6. 加載屏幕WinRT c#
- 7. 如何加載字體文件並在C#中使用其字體樣式?
- 8. WinRT中的字體不起作用
- 9. CKEditor外部字體加載在字體的下拉列表
- 10. 在WinRT應用程序中使用ISupportIncrementalLoading加載圖像
- 11. WinRT:使用GetFileFromApplicationUriAsync()加載靜態數據
- 12. 在c中加載位圖字體
- 13. 是否可以使用XmlDocument加載xml-url列表? (C#)
- 14. 無法使用加載的字體
- 15. 使用WinRT在C#中Ping網站
- 16. 使用C獲取WinRT中的可用磁盤空間#
- 17. 在WinRT中使用MVVMCross增量加載GridView
- 18. 可在Windows中使用的字體,但不能在iOS中使用的字體
- 19. 在Linux中列出可用字體
- 20. 是否可以使用已經在父窗口中下載的字體在子iframe中使用的字體?
- 21. 在CKeditor中添加可用字體
- 22. Marlett字體:我可以加載和WinAPI的使用
- 23. 在C#中使用列表
- 24. 在C#中使用列表
- 25. 在c中使用列表#
- 26. 如何使用InputStream加載字體
- 27. 使用Windows API加載ttf字體
- 28. 無法使用@ font-face加載字體
- 29. 使用Titanium SDK動態加載字體
- 30. 使用Angular 2動態加載字體
Thankyou是不是有一種原生的方式來做到這一點? – Yohannes
DirectWrite是原生的方式! :)我的意思是如果你想要混合語言,你可以跳過SharpDX並從C++中調用它,但是不,在WinRT中似乎沒有一種非DirectWrite方法。 –