-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
89 lines (70 loc) · 2.67 KB
/
App.xaml.cs
File metadata and controls
89 lines (70 loc) · 2.67 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System.Runtime.InteropServices;
using CodingWithCalvin.VSToolbox.Services;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml.Navigation;
using Windows.Graphics;
namespace CodingWithCalvin.VSToolbox;
public partial class App : Application
{
private Window? _window;
private AppWindow? _appWindow;
private TrayIconService? _trayIconService;
public App()
{
InitializeComponent();
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
_window = new Window
{
Title = "Visual Studio Toolbox"
};
// Get the AppWindow for advanced window control
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(_window);
var windowId = Win32Interop.GetWindowIdFromWindow(hwnd);
_appWindow = AppWindow.GetFromWindowId(windowId);
// Set the window/taskbar icon
var iconPath = Path.Combine(AppContext.BaseDirectory, "Assets", "vs2026_icon.ico");
if (File.Exists(iconPath))
{
_appWindow.SetIcon(iconPath);
}
// Set up the main content
var rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
_window.Content = rootFrame;
_ = rootFrame.Navigate(typeof(MainPage), e.Arguments);
// Initialize system tray
_trayIconService = new TrayIconService();
_trayIconService.Initialize(_window);
// Handle window close to minimize to tray instead
_appWindow.Closing += OnAppWindowClosing;
// Set window size and position to bottom-right
PositionWindowBottomRight(540, 600);
_window.Activate();
}
private void PositionWindowBottomRight(int width, int height)
{
if (_appWindow is null) return;
// Get the display area for the window
var displayArea = DisplayArea.GetFromWindowId(_appWindow.Id, DisplayAreaFallback.Primary);
var workArea = displayArea.WorkArea;
// Calculate bottom-right position with some padding
var padding = 12;
var x = workArea.X + workArea.Width - width - padding;
var y = workArea.Y + workArea.Height - height - padding;
_appWindow.MoveAndResize(new RectInt32(x, y, width, height));
}
private void OnAppWindowClosing(AppWindow sender, AppWindowClosingEventArgs args)
{
// Prevent window from closing - hide it instead
args.Cancel = true;
// Hide the window
_appWindow?.Hide();
}
private void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new InvalidOperationException($"Failed to load Page {e.SourcePageType.FullName}");
}
}