首先在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>