bunch ov fixes

This commit is contained in:
TheXamlGuy
2024-01-28 14:57:56 +00:00
parent 9f6cc35bc1
commit 6d40220412
28 changed files with 238 additions and 249 deletions
+27 -13
View File
@@ -1,24 +1,38 @@
using System.Runtime.CompilerServices;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls.Primitives;
using System.Reflection;
using System.Runtime.CompilerServices;
using WinRT;
namespace Hyperbar.UI.Windows;
public static class IWinRTObjectExtensions
{
public static void InitializeComponent<TComponent>(this TComponent component,
ref bool loaded,
[CallerFilePath] string path = "")
where TComponent :
IWinRTObject
public static void InitializeComponent<TComponent>(this TComponent component,
ref bool loaded, [CallerFilePath] string path = "")
where TComponent : IWinRTObject
{
if (loaded)
if (!loaded)
{
return;
loaded = true;
Type type = component.GetType();
if (type.Assembly is Assembly assembly && Path.GetDirectoryName(assembly.Location) is string assemblyDirectory)
{
string resourceName = Path.GetFileNameWithoutExtension(path);
string[] pathParts = path.Split(Path.DirectorySeparatorChar)[..^1];
string? resourcePath = pathParts
.Reverse()
.Select(part => Path.Combine(assemblyDirectory, part, resourceName))
.FirstOrDefault(File.Exists);
if (resourcePath is not null)
{
Application.LoadComponent(component, new Uri($"ms-appx:///{resourcePath.Replace('\\', '/')}"),
ComponentResourceLocation.Nested);
}
}
}
loaded = true;
//Uri resourceLocator = ApplicationExtensionHost.Current.LocateResource(component, callerFilePath);
//Application.LoadComponent(component, resourceLocator, ComponentResourceLocation.Nested);
}
}