【问题标题】:System.Runtime vs mscorlib in a CompositeFontCompositeFont 中的 System.Runtime 与 mscorlib
【发布时间】:2019-12-29 15:36:30
【问题描述】:

我们正在将 WPF 应用程序从 .NET Framework 迁移到 .NET Core 3.1。 在处理此问题时,我必须将 xaml 中的所有引用从 xmlns:system="clr-namespace:System;assembly=mscorlib" 交换为 xmlns:system="clr-namespace:System;assembly=System.Runtime"。非常有意义,mscorlib 用于 .NET Framework,System.Runtime 用于 .NET Core。阅读更多here

启动应用程序时,我发现没有加载复合字体的问题。因为我只是将mscorlib 替换为System.Runtime,所以文件看起来像这样:

<FontFamily xmlns="http://schemas.microsoft.com/winfx/2006/xaml/composite-font"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:system="clr-namespace:System;assembly=System.Runtime">

    <!-- Name mapping -->
    <FontFamily.FamilyNames>
        <system:String x:Key="en-US">My Font</system:String>
    </FontFamily.FamilyNames>
    <FontFamily.FamilyMaps>
    ...
    </FontFamily.FamilyMaps>
</FontFamily>

但我还是有问题。所以我将这个文件改回使用 mscorlib,如下所示:

<FontFamily xmlns="http://schemas.microsoft.com/winfx/2006/xaml/composite-font"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:system="clr-namespace:System;assembly=mscorlib">

    <!-- Name mapping -->
    <FontFamily.FamilyNames>
        <system:String x:Key="en-US">Cabo Font</system:String>
    </FontFamily.FamilyNames>
    <FontFamily.FamilyMaps>
    ...
    </FontFamily.FamilyMaps>
</FontFamily>

现在一切都很完美。

有人能很好地解释为什么会这样吗?

【问题讨论】:

  • 编码有问题或字体相关问题您能解释一下,您遇到了什么问题吗?
  • 问题是没有加载复合字体。有一些 unicode 映射到不同的字体。但主要问题是它没有加载。
  • 您的应用中是否默认启用了en-US 文化?
  • 我认为您误解了这个问题。现在一切正常。我想知道它为什么有效。为什么引用System.Runtime 不起作用,但使用mscorlib 起作用。

标签: wpf .net-core fonts .net-4.0


【解决方案1】:

在处理此问题时,我必须将 xaml 中的所有引用从 xmlns:system="clr-namespace:System;assembly=mscorlib" 交换为 xmlns:system="clr-namespace:System;assembly=System.Runtime"

您不必这样做,因为任何对mscorlib 的引用都会自动转发到System.Runtimehttps://github.com/dotnet/wpf/issues/708

这意味着您在以 .NET Framework 为目标时使用的标记在您以 .NET Core 为目标时也应该可以工作。

【讨论】:

  • 引用clr-namespace:System;assembly=mscorlib 实际上会给出设计时错误,但不会出现构建或运行时错误。这一定是 Visual Studio 中的错误。
猜你喜欢
  • 1970-01-01
  • 2014-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多