首先在CommandClass的构造器里面写上
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
然后写上方法的具体内容 CurrentDomain_AssemblyResolve;
public Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var name = args.Name.Split(',')[0];
var assembly = Assembly.GetAssembly(typeof(StartCommand));
var location = assembly.Location;
var dirPath = System.IO.Path.GetDirectoryName(location);
var dirInfo = new DirectoryInfo(dirPath);
foreach (var item in dirInfo.GetFiles())
{
//Assembly.LoadFile(item.FullName);
if (System.IO.Path.GetFileNameWithoutExtension(item.FullName) == name)
{
return Assembly.LoadFile(item.FullName);
}
}
Assembly ass = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().FullName.Split(',')[0] == name);
if (ass != null)
{
return ass;
}
return null;
}
关于materialdesign的内容为:
将引入materialdesign从application中拆成一个单独资源文件BaseUIResources.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<materialDesign:BundledTheme
BaseTheme="Light"
PrimaryColor="Cyan"
SecondaryColor="Cyan" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
然后在wpf的窗口/控件中引入BaseUIResources.xaml
<UserControl
x:Class="PlugInsManager.Views.PlugManagerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:convertLocation="clr-namespace:PlugInsManager.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:local="clr-namespace:PlugInsManager.Views"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://prismlibrary.com/"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="BaseUIResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
</UserControl>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?