iNKORE-NET / UI.WPF.Modern

Modern (Fluent 2) styles and controls for your WPF applications
GNU Lesser General Public License v2.1
447 stars 39 forks source link

How to Load/Use UI.WPF.Modern in VSIX Extension/Template? #23

Closed ghost1372 closed 10 months ago

ghost1372 commented 10 months ago

if you want to use this library in a vsix extension/template you will get FileNotFound exception. The reason for this error is the failure to load assemblies. so for fixing this issue, we have 2 ways:

1.Add this line in top of your package class:

[ProvideBindingPath]
public sealed class YOURPROJECTPackage : AsyncPackage

Or we can use a AssemblyResolver:

AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;

private Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
{
    string path = Assembly.GetExecutingAssembly().Location;
    path = Path.GetDirectoryName(path);

    if (args.Name.ToLower().Contains("iNKORE.UI.WPF.Modern") && !args.Name.ToLower().Contains("iNKORE.UI.WPF.Modern.Controls"))
    {
        path = Path.Combine(path, "iNKORE.UI.WPF.Modern.dll");
        Assembly ret = Assembly.LoadFrom(path);
        return ret;
    }
 if (args.Name.ToLower().Contains("iNKORE.UI.WPF.Modern.Controls"))
    {
        path = Path.Combine(path, "iNKORE.UI.WPF.Modern.Controls.dll");
        Assembly ret = Assembly.LoadFrom(path);
        return ret;
    }
    return null;
}
NotYoojun commented 10 months ago

Ok, I will add these to the FAQ doc later, thks!

NotYoojun commented 10 months ago

Now it has been added, thanks!