-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
43 lines (39 loc) · 1.2 KB
/
App.xaml.cs
File metadata and controls
43 lines (39 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
namespace ResourcesWidget
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
void App_Startup(object sender, StartupEventArgs e)
{
//This is used to load the assembly from the resources instead of having it as standalone dll
AppDomain.CurrentDomain.AssemblyResolve += (se, args) =>
{
Assembly thisAssembly = Assembly.GetExecutingAssembly();
//Get the Name of the AssemblyFile
var name = args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll";
//Load form Embedded Resources - This Function is not called if the Assembly is in the Application Folder
var resources = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(name));
if (resources.Any())
{
var resourceName = resources.First();
using (Stream stream = thisAssembly.GetManifestResourceStream(resourceName))
{
if (stream == null) return null;
var block = new byte[stream.Length];
stream.Read(block, 0, block.Length);
return Assembly.Load(block);
}
}
return null;
};
new MyWidget().Show();
}
}
}