WPF Glyphs 控制字体 uri!(它很慢并且保留在内存中)

WPF Glyphs control font uri!(its slow and remains in memory)

我正在制作一个类似数据网格的控件,其中包含很多行和列。使用字形而不是文本块解决了加载时间问题。

现在的问题是,当我从应用程序包中给它一个字体时,它会变慢并保留在内存中,并且每次重新加载控件时它都会变慢并消耗更多内存:

        Glyphs glyph = new Glyphs()
        {
                FlowDirection = FlowDirection.LeftToRight,
                UnicodeString = "text",
                FontUri = fnt,
                FontRenderingEmSize = 15,
                Fill = Brushes.Black,
                HorizontalAlignment = HorizontalAlignment.Center
        };

现在导致问题的原因是:

 Uri fnt = new Uri("pack://application:,,,/myapp;component/Fonts/times.ttf");

如果我这样做,一切都很好:

 Uri fnt = new Uri(@"C:\Windows\Fonts\times.ttf");

但我要使用其他系统上不存在的字体,它需要与我的应用程序一起使用。

这实际上和这里的问题是一样的 and it's not going to be fixed anytime soon as following answer was made on 2013.10.01:

The WPF team has recently reviewed this issue and will not be addressing this issue as at this time the team is focusing on the bugs impacting the highest number of WPF developers. If you believe that this was resolved in error, please reactivate this bug with any necessary supporting details.

We appreciate the feedback. However, this issue will not be addressed in the next version of WPF. Thank you. –WPF Team.

由于这两种情况都是由UnmanagedMemoryStreams引起的,目前您只能制作临时文件夹并将字体保存到其中。它不漂亮,但就是我们所拥有的。