You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MaterialDesignXAMLToolkit配置失败求助(WPF/XAML新手)

MaterialDesignXAMLToolkit配置报错:找不到指定资源文件

针对你遇到的找不到MaterialDesignTheme.Defaults.xaml资源文件的问题,给你几个排查和解决的方向:

1. 检查NuGet包安装状态

先卸载已安装的MaterialDesignThemes和ShowMeTheXAML,重新安装最新稳定版。安装时确保勾选你的目标项目,安装完成后查看项目引用列表,确认这两个包已经被正确添加。

2. 修正App.xaml的资源引用逻辑

新版本的MaterialDesignThemes中,materialDesign:BundledTheme已经整合了默认样式资源,不需要再单独引用MaterialDesignTheme.Defaults.xaml。删掉那行多余的资源字典引用即可,修改后的App.xaml代码如下:

<Application x:Class="MaterialDesign_TEST.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="DeepPurple" SecondaryColor="Lime" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
</Application>

3. 清理重建项目

右键项目选择清理,完成后再选择生成,最后运行项目。这一步能解决很多因缓存或编译问题导致的资源引用错误。

如果还是报错,检查是否遗漏了MaterialDesignColorsNuGet包——部分版本的MaterialDesignThemes依赖这个包,不过正常安装主包时会自动安装依赖,若没有则手动安装即可。

内容的提问来源于stack exchange,提问作者Myslatron

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 09:52:46