【问题标题】:Resource from ResourceDictionary in UWP app only recognized on Xbox来自 UWP 应用中 ResourceDictionary 的资源仅在 Xbox 上识别
【发布时间】:2020-08-10 13:11:24
【问题描述】:

我正在处理的一个项目发生了一个特殊问题。当应用在 PC 上本地运行时,添加到 UWP app 的资源字典中的某些资源无法识别,但在 Xbox 上运行时可以识别。

从 Visual Studio 在 PC (Debug|x64) 上运行应用程序时,启动时会弹出以下异常:

Windows.UI.Xaml.Markup.XamlParseException
  HResult=0x802B000A
  Message=The text associated with this error code could not be found.

Cannot find a Resource with the Name/Key SimpleTextBox [Line: 45 Position: 41]
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

此异常在InitializeComponent method of LoginView.xaml.cs 上触发。

样式定义为hereResourceDictionary 包含在here

【问题讨论】:

  • 如果您将 JellyfinStyleResources.DeviceFamily-Desktop.xaml 文件移动到另一个文件夹或重命名 JellyfinStyleResources.xaml(例如 JellyfinStyleResources1.xaml)并再次合并此文件(&lt;ResourceDictionary Source="Resources/JellyfinStyleResources1.xaml"/&gt; ),会出现同样的问题吗?

标签: uwp uwp-xaml xbox-one


【解决方案1】:

我下载了原始示例repo,在xbox上运行确实成功,在PC上运行失败,提示

Cannot find a Resource with the Name/Key ViewModelLocator [Line: 8 Position: 5]'

所以我们需要在文件JellyfinStyleResources.DeviceFamily-Desktop.xaml 中添加一个ViewModelLocator 密钥。

我们这样做是因为在 xbox 上,应用会在没有指定平台的情况下加载 JellyfinStyleResources。但是在 PC 上,存在一个名为 JellyfinStyleResources.DeviceFamily-Desktop.xaml 的文件。我们的应用会自动加载它的平台相关文件。

那么在我们添加上面的键之后,编译器会提示更多关于资源丢失的错误。对比这两个文件,你会发现,作者只为xbox写的,所以需要将资源复制到文件JellyfinStyleResources.DeviceFamily-Desktop.xaml

全部完成后,您会发现应用程序将在您的 PC 上成功运行 :)


或者您可以删除文件JellyfinStyleResources.DeviceFamily-Desktop.xaml,运行应用程序并完成:)

【讨论】:

    猜你喜欢
    • 2016-04-02
    • 2016-07-30
    • 2020-09-11
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    • 2018-01-24
    • 2018-07-23
    相关资源
    最近更新 更多