无法解析资源

问题描述 投票:0回答:3

我在 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>

我已经尝试了资源“x”无法解析。但这会导致项目无法运行(我相信在尝试使用建议的“绝对包URI”时我没有使用正确的路径”)。所以我现在有两个问题:

  1. 考虑到我在 App.xaml 中定义资源的方式,资源在 XAML 设计器中无法解析是否有原因(根据开发人员指南:https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/wiki/Getting-Started) )?
  2. 如何找到用于资源字典源的“绝对包 URI”?
c# wpf xaml material-design-in-xaml
3个回答
1
投票

以前我也遇到过这样的问题。 错误原因如下。

1。设置和设置配置

关于这个请查看github和Material Design主页。

2。构建和编译问题

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


0
投票

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

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

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

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

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

0
投票

请记住,这对于 5.0.0 版本不再有效。默认主题不存在。您需要使用其他的:

https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/issues/3485

ps:在文档中仍然使用默认值,因此它会失败。 所以使用

<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign2.Defaults.xaml" />

ps2:AI也在撒谎,不要相信他们-.-

© www.soinside.com 2019 - 2024. All rights reserved.