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

基于.NET 4.7.2的WPF项目加载MaterialDesign库失败求助

解决WPF Framework 4.7.2中MaterialDesign库加载失败问题
  • 确认包版本兼容性
    部分新版本MaterialDesignThemes.Wpf可能对.NET Framework 4.7.2支持有限,建议安装明确标注支持net472的版本。在NuGet包管理器中,为MaterialDesignThemes.Wpf和MaterialDesignColors选择v4.9.0及以下版本(或查看包详情的目标框架支持列表)。

  • 验证程序集引用的“复制本地”设置
    右键项目→引用→找到MaterialDesignThemes.Wpf和MaterialDesignColors→属性→确保复制本地设置为True。若该选项为False,运行时程序集不会被复制到输出目录,会导致加载失败。

  • 检查Pack URI路径正确性
    确认App.xaml中的资源字典路径拼写完全正确,包括程序集名称和文件路径:

    <Application x:Class="DesfireCodificatoreWPF.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:materialDesign="https://materialdesigninxaml.net/winfx/xaml/themes"
             StartupUri="MainWindow.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.DeepPurple.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    </Application>
    

    注意程序集名称MaterialDesignThemes.Wpf和MaterialDesignColors必须与NuGet包的程序集名称一致,文件路径要匹配包内的实际结构。

  • 清理并重建项目

    1. 删除项目目录下的bin和obj文件夹
    2. 在Visual Studio中选择菜单→生成→清理解决方案
    3. 重新生成解决方案,确保无编译错误后再运行
  • 确认项目目标框架
    右键项目→属性→应用程序→确认目标框架为.NET Framework 4.7.2,避免因框架版本不匹配引发加载问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 01:27:51