private void TitlebarBrandingBtn_Click(object sender, RoutedEventArgs e) { _mainAppWindow.TitleBar.ResetToDefault(); _isBrandedTitleBar = !_isBrandedTitleBar; // Check to see if customization is supported. Currently only supported on Windows 11. if (AppWindowTitleBar.IsCustomizationSupported() && _isBrandedTitleBar) { _mainAppWindow.Title = "Default titlebar with custom color customization"; _mainAppWindow.TitleBar.ForegroundColor = Colors.White; _mainAppWindow.TitleBar.BackgroundColor = Colors.DarkOrange; _mainAppWindow.TitleBar.InactiveBackgroundColor = Colors.Blue; _mainAppWindow.TitleBar.InactiveForegroundColor = Colors.White; // Buttons _mainAppWindow.TitleBar.ButtonBackgroundColor = Colors.DarkOrange; _mainAppWindow.TitleBar.ButtonForegroundColor = Colors.White; _mainAppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Blue; _mainAppWindow.TitleBar.ButtonInactiveForegroundColor = Colors.White; _mainAppWindow.TitleBar.ButtonHoverBackgroundColor = Colors.Green; _mainAppWindow.TitleBar.ButtonHoverForegroundColor = Colors.White; _mainAppWindow.TitleBar.ButtonPressedBackgroundColor = Colors.DarkOrange; _mainAppWindow.TitleBar.ButtonPressedForegroundColor = Colors.White; } else { _mainAppWindow.Title = MainWindow.WindowTitle; } _mainWindow.MyTitleBar.Visibility = Visibility.Collapsed; }
private void titlebarCustomBtn_Click(object sender, EventArgs e) { _mainAppWindow.TitleBar.ExtendsContentIntoTitleBar = !_mainAppWindow.TitleBar.ExtendsContentIntoTitleBar; // Check to see if customization is supported. Currently only supported on Windows 11. if (AppWindowTitleBar.IsCustomizationSupported() && _mainAppWindow.TitleBar.ExtendsContentIntoTitleBar) { // Show the custom titlebar MyTitleBar.Visible = true; // Set Button colors to match the custom titlebar _mainAppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent; _mainAppWindow.TitleBar.ButtonForegroundColor = Colors.White; _mainAppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent; _mainAppWindow.TitleBar.ButtonInactiveForegroundColor = Colors.White; _mainAppWindow.TitleBar.ButtonHoverBackgroundColor = Colors.Green; _mainAppWindow.TitleBar.ButtonHoverForegroundColor = Colors.White; _mainAppWindow.TitleBar.ButtonPressedBackgroundColor = Colors.Green; _mainAppWindow.TitleBar.ButtonPressedForegroundColor = Colors.White; // Set the drag region for the custom TitleBar SetDragRegionForCustomTitleBar(_mainAppWindow); } else { // Bring back the default titlebar MyTitleBar.Visible = false; _mainAppWindow.TitleBar.ResetToDefault(); } }
public MainWindow() { this.InitializeComponent(); m_AppWindow = GetAppWindowForCurrentWindow(); // Check to see if customization is supported. // Currently only supported on Windows 11. if (AppWindowTitleBar.IsCustomizationSupported()) { var titleBar = m_AppWindow.TitleBar; titleBar.ExtendsContentIntoTitleBar = true; AppTitleBar.Loaded += AppTitleBar_Loaded; AppTitleBar.SizeChanged += AppTitleBar_SizeChanged; BackButton.Click += OnBackClicked; BackButton.Visibility = Visibility.Collapsed; } else { // Title bar customization using these APIs is currently // supported only on Windows 11. In other cases, hide // the custom title bar element. // AppTitleBar.Visibility = Visibility.Collapsed; // TODO Show alternative UI for any functionality in // the title bar, such as the back button, if used } }
private void AppTitleBar_SizeChanged(object sender, SizeChangedEventArgs e) { if (AppWindowTitleBar.IsCustomizationSupported() && m_AppWindow.TitleBar.ExtendsContentIntoTitleBar) { // Update drag region if the size of the title bar changes. SetDragRegionForCustomTitleBar(m_AppWindow); } }
private void AppTitleBar_Loaded(object sender, RoutedEventArgs e) { SetTitleBar(AppTitleBar); // TODO Raname MainPage in case your app Main Page has a different name PageFrame.Navigate(typeof(MainPage)); if (AppWindowTitleBar.IsCustomizationSupported()) { SetDragRegionForCustomTitleBar(m_AppWindow); } }
private void TitlebarCustomBtn_Click(object sender, RoutedEventArgs e) { _mainAppWindow.TitleBar.ExtendsContentIntoTitleBar = !_mainAppWindow.TitleBar.ExtendsContentIntoTitleBar; // Check to see if customization is supported. Currently only supported on Windows 11. if (AppWindowTitleBar.IsCustomizationSupported() && _mainAppWindow.TitleBar.ExtendsContentIntoTitleBar) { // Show the custom titlebar _mainWindow.MyTitleBar.Visibility = Visibility.Visible; // Set Button colors to match the custom titlebar _mainAppWindow.TitleBar.ButtonBackgroundColor = Colors.Blue; _mainAppWindow.TitleBar.ButtonForegroundColor = Colors.White; _mainAppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Blue; _mainAppWindow.TitleBar.ButtonInactiveForegroundColor = Colors.White; _mainAppWindow.TitleBar.ButtonHoverBackgroundColor = Colors.Green; _mainAppWindow.TitleBar.ButtonHoverForegroundColor = Colors.White; _mainAppWindow.TitleBar.ButtonPressedBackgroundColor = Colors.Green; _mainAppWindow.TitleBar.ButtonPressedForegroundColor = Colors.White; //Infer titlebar height int titleBarHeight = _mainAppWindow.TitleBar.Height; _mainWindow.MyTitleBar.Height = titleBarHeight; // Get caption button occlusion information // Use LeftInset if you've explicitly set your window layout to RTL or if app language is a RTL language int CaptionButtonOcclusionWidth = _mainAppWindow.TitleBar.RightInset; // Define your drag Regions int windowIconWidthAndPadding = (int)_mainWindow.MyWindowIcon.ActualWidth + (int)_mainWindow.MyWindowIcon.Margin.Right; int dragRegionWidth = _mainAppWindow.Size.Width - (CaptionButtonOcclusionWidth + windowIconWidthAndPadding); Windows.Graphics.RectInt32[] dragRects = new Windows.Graphics.RectInt32[] { }; Windows.Graphics.RectInt32 dragRect; dragRect.X = windowIconWidthAndPadding; dragRect.Y = 0; dragRect.Height = titleBarHeight; dragRect.Width = dragRegionWidth; var dragRectsArray = dragRects.Append(dragRect).ToArray(); _mainAppWindow.TitleBar.SetDragRectangles(dragRectsArray); } else { // Bring back the default titlebar _mainWindow.MyTitleBar.Visibility = Visibility.Collapsed; _mainAppWindow.TitleBar.ResetToDefault(); } }
private void SetTitleBarColorsAndIcon() { IntPtr hWnd = WindowNative.GetWindowHandle(this); WindowId windowId = Win32Interop.GetWindowIdFromWindow(hWnd); AppWindow appWindow = AppWindow.GetFromWindowId(windowId); // Title bar customization is not supported on Windows 10 if (AppWindowTitleBar.IsCustomizationSupported()) { AppWindowTitleBar titleBar = appWindow.TitleBar; ResourceDictionary dictionary = null; switch (Settings.Instance.AppTheme) { case ElementTheme.Default: dictionary = Application.Current.Resources; break; case ElementTheme.Light: dictionary = (ResourceDictionary)Application.Current.Resources.ThemeDictionaries["Light"]; break; case ElementTheme.Dark: dictionary = (ResourceDictionary)Application.Current.Resources.ThemeDictionaries["Dark"]; break; } titleBar.BackgroundColor = (Color?)dictionary["TitleBarBackgroundColor"]; titleBar.ForegroundColor = (Color?)dictionary["TitleBarForegroundColor"]; titleBar.InactiveBackgroundColor = (Color?)dictionary["TitleBarInactiveBackgroundColor"]; titleBar.InactiveForegroundColor = (Color?)dictionary["TitleBarInactiveForegroundColor"]; titleBar.ButtonBackgroundColor = (Color?)dictionary["TitleBarButtonBackgroundColor"]; titleBar.ButtonHoverBackgroundColor = (Color?)dictionary["TitleBarButtonHoverBackgroundColor"]; titleBar.ButtonForegroundColor = (Color?)dictionary["TitleBarButtonForegroundColor"]; titleBar.ButtonHoverForegroundColor = (Color?)dictionary["TitleBarButtonHoverForegroundColor"]; titleBar.ButtonPressedBackgroundColor = (Color?)dictionary["TitleBarButtonPressedBackgroundColor"]; titleBar.ButtonPressedForegroundColor = (Color?)dictionary["TitleBarButtonPressedForegroundColor"]; titleBar.ButtonInactiveBackgroundColor = (Color?)dictionary["TitleBarButtonInactiveBackgroundColor"]; titleBar.ButtonInactiveForegroundColor = (Color?)dictionary["TitleBarButtonInactiveForegroundColor"]; } string applicationRoot = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); appWindow.SetIcon(Path.Combine(applicationRoot, @"Assets\Logo.ico")); }
private void SetDragRegionForCustomTitleBar(AppWindow appWindow) { if (AppWindowTitleBar.IsCustomizationSupported() && appWindow.TitleBar.ExtendsContentIntoTitleBar) { double scaleAdjustment = GetScaleAdjustment(); RightPaddingColumn.Width = new GridLength(appWindow.TitleBar.RightInset / scaleAdjustment); LeftPaddingColumn.Width = new GridLength(appWindow.TitleBar.LeftInset / scaleAdjustment); List <Windows.Graphics.RectInt32> dragRectsList = new(); Windows.Graphics.RectInt32 dragRectL; dragRectL.X = (int)((LeftPaddingColumn.ActualWidth + IconColumn.ActualWidth) * scaleAdjustment); dragRectL.Y = 0; dragRectL.Height = (int)((AppTitleBar.ActualHeight) * scaleAdjustment); dragRectL.Width = (int)((TitleColumn.ActualWidth + DragColumn.ActualWidth) * scaleAdjustment); dragRectsList.Add(dragRectL); Windows.Graphics.RectInt32[] dragRects = dragRectsList.ToArray(); appWindow.TitleBar.SetDragRectangles(dragRects); } }