Stuff for tunesync

This commit is contained in:
Dan Clark
2024-11-16 19:46:25 +00:00
parent 0865e7da89
commit b5bf17821c
27 changed files with 562 additions and 58 deletions
+32
View File
@@ -0,0 +1,32 @@
using Microsoft.UI.Xaml;
using System.Diagnostics.CodeAnalysis;
namespace Toolkit.WinUI;
public class WindowRegistry :
IWindowRegistry
{
private readonly List<Window> windows = [];
public void Add(Window window)
{
if (!windows.Contains(window))
{
void OnWindowClosed(object sender, WindowEventArgs args)
{
window.Closed -= OnWindowClosed;
windows.Remove(window);
}
windows.Add(window);
window.Closed += OnWindowClosed;
}
}
public bool TryGet<TWindow>([DisallowNull] out TWindow? window)
where TWindow : Window
{
window = windows.OfType<TWindow>().FirstOrDefault() ?? null;
return window is not null;
}
}