I am using depency injection, to create the man window
public partial class App : Application {
private IHost _host;
public App() {
InitializeComponent();
}
protected override void OnLaunched(LaunchActivatedEventArgs args) {
_host = Host.CreateDefaultBuilder()
.ConfigureServices(ConfigureServices)
.Build();
// Start the host
_host.Start();
// Resolve and activate the main window using dependency injection
var mainWindow = _host.Services.GetRequiredService<NavWindow>();
mainWindow.Activate();
}
private void ConfigureServices(IServiceCollection services) {
// Register your dependencies here
services.AddSingleton<NavWindowViewModel>();
services.AddSingleton(provider => new NavWindow(provider.GetRequiredService<NavWindowViewModel>()));
services.AddSingleton<SubjectsPageViewModel>();
// Add other services as needed
}
}
}
What I want to do is that every time I create a new Wndows, it will have a tranparent tiitle bar.
I found this
https://learn.microsoft.com/en-us/windows/apps/develop/title-bar?msclkid=e23d7633cf9311eca704e47ee540cf97&tabs=wasdk#simple-customization
and I implemented it but I get

I want something like

I dont want to do this in every window
private AppWindow m_AppWindow;
public NavWindowViewModel ViewModel { get; set; }
public NavWindow(NavWindowViewModel viewModel) {
InitializeComponent();
ViewModel = viewModel;
ExtendsContentIntoTitleBar = true;
SetTitleBarColors();
// Subscribe to the message
WeakReferenceMessenger.Default.Register<NavigationViewItem>(this,
HandleSelectedItemMessage);
}
private void HandleSelectedItemMessage(object recipient, NavigationViewItem message) {
if (message != null) {
var tag = message.Tag.ToString();
NavFrame.Navigate(PageTypeMapper.PageTypeDictionary[tag]);
}
}
private bool SetTitleBarColors() {
// Check to see if customization is supported.
// The method returns true on Windows 10 since Windows App SDK 1.2, and on all versions of
// Windows App SDK on Windows 11.
if (AppWindowTitleBar.IsCustomizationSupported()) {
if (m_AppWindow is null) {
m_AppWindow = GetAppWindowForCurrentWindow();
}
var titleBar = m_AppWindow.TitleBar;
// Set active window colors
// Note: No effect when app is running on Windows 10 since color customization is not
// supported.
titleBar.ForegroundColor = Colors.Transparent;
titleBar.ButtonForegroundColor = Colors.Transparent;
titleBar.ButtonBackgroundColor = Colors.Transparent;
titleBar.ButtonHoverForegroundColor = Colors.Transparent;
titleBar.ButtonHoverBackgroundColor = Colors.DarkSeaGreen;
titleBar.ButtonPressedForegroundColor = Colors.Gray;
titleBar.ButtonPressedBackgroundColor = Colors.LightGreen;
// Set inactive window colors
// Note: No effect when app is running on Windows 10 since color customization is not
// supported.
titleBar.InactiveForegroundColor = Colors.Gainsboro;
titleBar.InactiveBackgroundColor = Colors.SeaGreen;
titleBar.ButtonInactiveForegroundColor = Colors.Gainsboro;
titleBar.ButtonInactiveBackgroundColor = Colors.SeaGreen;
return true;
}
return false;
}
private AppWindow GetAppWindowForCurrentWindow() {
IntPtr hWnd = WindowNative.GetWindowHandle(this);
WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);
return AppWindow.GetFromWindowId(wndId);
}
}
}
The problem with this approach is that is for a specific Window, what happends if I create a new one?
Also it overlaps my navView
Code: https://github.com/eduardoagr/Demy-AI/tree/master/Demy