【问题标题】:Unable to Resolve Resources无法解决资源
【发布时间】:2019-12-13 10:20:41
【问题描述】:

我在 WPF 中使用 MaterialDesign for XAML 包。当我运行我的应用程序时,所有样式和控件都按预期呈现。然而,在 XAML 设计器中,我遇到了许多错误,例如“无法解析资源‘MaterialDesignFlatButton’”。抛出该错误的行示例:

<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 8 0" ...

我的app.xaml内容如下:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>

            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.LightBlue.xaml" />

        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

我尝试了The resource "x" could not be resolved. 上提出的最佳解决方案,但这会导致项目无法运行(我相信在尝试使用建议的“绝对包 URI”时我没有使用正确的路径)。所以我现在有两个问题:

  1. 鉴于我在 App.xaml 中定义资源的方式(根据开发人员指南:https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/wiki/Getting-Started),XAML 设计器中的资源无法解析是否有原因?
  2. 如何找到“绝对包 URI”以用作我的资源字典的来源?

【问题讨论】:

  • 你有没有设法解决这个问题?

标签: c# wpf xaml material-design-in-xaml


【解决方案1】:

过去,我遇到过这样的问题。 错误原因如下。

1.设置和设置配置

关于这个,请查看github和material design homepage。

2.构建和编译问题

对此,用户可以将“平台目标”设置为“x64”。 这可能会引发错误,因为 Material Designer 工具使用“x32”编译器,所以请使用“any cpu”或“x32”。

【讨论】:

    【解决方案2】:

    我在使用扁平重音按钮时遇到了这个问题,而其他所有按钮样式都有效。我添加了按钮的资源,然后错误就消失了。然后我删除了按钮资源......并且错误仍然消失了。

    https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/wiki/FAQ

    异常:找不到名为“MaterialDesign...”的资源

    当您有静态资源引用时,通常会出现此错误 材料设计风格之一,并没有包括 包含样式的适当资源字典。试试 以下:

    • 确保您已在 App.xaml 中加载了所有默认材料设计样式。您可以在 Getting Started guide
    • 确保您已引用包含该样式的控件特定资源字典。这个路径是资源字典 应该是 .xaml" />。例如,如果您尝试引用 MaterialDesignFloatingActionMiniButton 样式的按钮, 资源字典源将是:.通常,这些包含在您的窗口的根目录下完成,用户 控制或模板。您可以找到资源的完整列表 字典在这里

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-18
      • 2015-08-07
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多