简体   繁体   English

来自 UWP 应用程序中 ResourceDictionary 的资源仅在 Xbox 上识别

[英]Resource from ResourceDictionary in UWP app only recognized on Xbox

There's a peculiar issue happening on a project I'm working on.我正在从事的一个项目发生了一个特殊的问题。 Certain resources added to resource dictionaries of an UWP app are not recognized when the app is being run locally on a PC, but they are recognized when run on an Xbox.当应用程序在 PC 上本地运行时,添加到UWP 应用程序的资源字典中的某些资源无法识别,但在 Xbox 上运行时可以识别它们。

When running the app on PC (Debug|x64) from Visual Studio, the following Exception pops up on startup:从 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>

This exception triggers on the InitializeComponent method of LoginView.xaml.cs .此异常在LoginView.xaml.cs 的 InitializeComponent 方法上触发。

The style is defined here and the ResourceDictionary is included here .样式在此处定义, ResourceDictionary包含在此处

I downloaded the original sample repo, and run it on xbox successfully indeed, and failed on PC, and hint我下载了原始示例 repo,确实在 xbox 上运行成功,在 PC 上运行失败,提示

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

So we need to add a ViewModelLocator key to file JellyfinStyleResources.DeviceFamily-Desktop.xaml .所以我们需要在JellyfinStyleResources.DeviceFamily-Desktop.xaml文件中添加一个ViewModelLocator键。

We do this, because on xbox, app will load JellyfinStyleResources without specified platform.我们这样做是因为在 xbox 上,应用会在没有指定平台的情况下加载JellyfinStyleResources But on PC, there exist a file named JellyfinStyleResources.DeviceFamily-Desktop.xaml .但是在 PC 上,存在一个名为JellyfinStyleResources.DeviceFamily-Desktop.xaml的文件。 Our app will automatically load it's platform related file.我们的应用程序将自动加载它的平台相关文件。

Then after we add the key above, the compiler will hint more errors about resources missing.然后在我们添加上面的键之后,编译器会提示更多关于资源丢失的错误。 If you compare the two files, you will find, the author only write them for xbox, so you need to copy the resources to file JellyfinStyleResources.DeviceFamily-Desktop.xaml .对比这两个文件,你会发现,作者只为xbox写的,所以需要将资源复制到文件JellyfinStyleResources.DeviceFamily-Desktop.xaml中。

After all done, you will find out the app will successfully run on your PC:)完成后,您会发现该应用程序将在您的 PC 上成功运行:)


Or you can just delete the file JellyfinStyleResources.DeviceFamily-Desktop.xaml , run app and done:)或者您可以删除文件JellyfinStyleResources.DeviceFamily-Desktop.xaml ,运行应用程序并完成:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM