【问题标题】:UWP: Using Windows.Desktop target device family triggers XamlParseException - brush not foundUWP:使用 Windows.Desktop 目标设备系列触发 XamlParseException - 找不到刷子
【发布时间】:2019-10-21 22:07:04
【问题描述】:

Package.appxmanifest 文件中进行了以下更改:

之前:

...
<Dependencies>
  <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
...
<Capabilities>
  <Capability Name="internetClient" />
</Capabilities>

之后:

...
<Dependencies>
  <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
...
<Capabilities>
  <Capability Name="internetClient" />
  <rescap:Capability Name="extendedBackgroundTaskTime" />
  <rescap:Capability Name="extendedExecutionUnconstrained" />
</Capabilities>

此外,还引入了一些 App.xaml.cs 逻辑来处理扩展执行,如本文所述(这对问题没有影响,因为删除它不会改变结果):

https://blogs.msdn.microsoft.com/mvpawardprogram/2018/01/30/non-suspending-uwp-desktop-apps/

在运行应用程序之前没有产生错误,但在进行上述更改后,它在打开页面时突然崩溃:

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 SystemControlBackgroundChromeBlackLowBrush [Line: 193 Position: 121]
  Source=Windows
  StackTrace:
   at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation)
   at ...EventsView.InitializeComponent() in ..Client\Application.UWP\obj\x86\Debug\Views\EventsView.g.i.cs:line 43
   at ..EventsView..ctor() in Client\Application.UWP\Views\EventsView.xaml.cs:line 25

EventsView.xaml.g.i.cs 第 43 行:

global::Windows.UI.Xaml.Application.LoadComponent(this, resourceLocator, global::Windows.UI.Xaml.Controls.Primitives.ComponentResourceLocation.Application);

EventsView.cs 第 25 行:

<DataTemplate x:Key="FooViewModelDetailsDataTemplate" x:DataType="viewmodels:FooViewModel">

我不确定将应用程序目标设备系列更改为Windows.Desktop 会如何突然导致应用程序无法找到某个画笔。

我已删除 XAML 和视图模型中的所有显式画笔分配(任何画笔),但错误仍然存​​在。

此外,代码库中的任何地方都没有(也不存在)任何使用名称 SystemControlBackgroundChromeBlackLowBrush 的代码。

【问题讨论】:

  • 我无法重现您的问题,而且我似乎没有像您一样的 XAML。那么您能否提供您的目标 SDK 版本、操作系统版本,然后向我们提供可以重现您的问题的项目。如果我只是使用博客中的演示,我这边什么都不会发生。
  • 我刚刚将博客文章中的代码和标记添加到我的项目中,该项目本身包含更多的 XAML。我一直在寻找关于我可能在做什么“错误”的线索。但我将尝试对问题进行最小限度的复制,以便完整的来源可供检查。做最少的复制似乎是本月的主题。 :-)
  • 仅供参考:这里的另一个类似案例:stackoverflow.com/questions/39714668/…
  • 罪魁祸首似乎是 Windows Community Toolkit 中的 BladeView 控件。将提交错误。
  • 好的。不要忘记在此处添加 git issue uri。或者我们不知道这个特定问题发生了什么。

标签: windows xaml uwp enterprise windows-community-toolkit


【解决方案1】:

可能有点晚了,但对于面临类似问题的任何人: 当我将 TargetDeviceFamily Name 从 Windows.Universal 更改为 Windows.Desktop 时,我的应用程序总是在启动时崩溃。 为了使它工作,我必须正确指定 MinVersion 和 MaxVersionTested,正如 Microsoft docs 中提到的那样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 2011-05-04
    • 2011-03-11
    相关资源
    最近更新 更多