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(); } }
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; }
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 Properties_Loaded(object sender, RoutedEventArgs e) { AppSettings.ThemeModeChanged += AppSettings_ThemeModeChanged; if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) { propWindow = Interaction.AppWindows[UIContext]; // Collect AppWindow-specific info TitleBar = propWindow.TitleBar; // Set properties window titleBar style TitleBar.ButtonBackgroundColor = Colors.Transparent; TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent; AppSettings.UpdateThemeElements.Execute(null); } }
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 async void Properties_Loaded(object sender, RoutedEventArgs e) { if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) { // Collect AppWindow-specific info propWindow = Interaction.AppWindows[UIContext]; // Set properties window titleBar style _TitleBar = propWindow.TitleBar; _TitleBar.ButtonBackgroundColor = Colors.Transparent; _TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent; App.AppSettings.UpdateThemeElements.Execute(null); } await ViewModel.GetPropertiesAsync(_tokenSource); }
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); } }
private async void Properties_Loaded(object sender, RoutedEventArgs e) { if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8)) { // Collect AppWindow-specific info propWindow = Interaction.AppWindows[UIContext]; // Set properties window titleBar style _TitleBar = propWindow.TitleBar; _TitleBar.ButtonBackgroundColor = Colors.Transparent; _TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent; App.AppSettings.UpdateThemeElements.Execute(null); } if (App.CurrentInstance.ContentPage.IsItemSelected) { var selectedItem = App.CurrentInstance.ContentPage.SelectedItem; IStorageItem selectedStorageItem = null; if (selectedItem.PrimaryItemAttribute == StorageItemTypes.File) { selectedStorageItem = await StorageFile.GetFileFromPathAsync(selectedItem.ItemPath); ItemProperties.ItemSize = selectedItem.FileSize; } else if (selectedItem.PrimaryItemAttribute == StorageItemTypes.Folder) { var storageFolder = await StorageFolder.GetFolderFromPathAsync(selectedItem.ItemPath); selectedStorageItem = storageFolder; GetFolderSize(storageFolder); } ItemProperties.ItemName = selectedItem.ItemName; ItemProperties.ItemType = selectedItem.ItemType; ItemProperties.ItemPath = selectedItem.ItemPath; ItemProperties.LoadFileIcon = selectedItem.LoadFileIcon; ItemProperties.LoadFolderGlyph = selectedItem.LoadFolderGlyph; ItemProperties.LoadUnknownTypeGlyph = selectedItem.LoadUnknownTypeGlyph; ItemProperties.ItemModifiedTimestamp = selectedItem.ItemDateModified; ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(selectedStorageItem.DateCreated); if (!App.CurrentInstance.ContentPage.SelectedItem.LoadFolderGlyph) { var thumbnail = await(await StorageFile.GetFileFromPathAsync(App.CurrentInstance.ContentPage.SelectedItem.ItemPath)).GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem, 80, Windows.Storage.FileProperties.ThumbnailOptions.ResizeThumbnail); var bitmap = new BitmapImage(); await bitmap.SetSourceAsync(thumbnail); ItemProperties.FileIconSource = bitmap; } if (selectedItem.PrimaryItemAttribute == StorageItemTypes.File) { // Get file MD5 hash var hashAlgTypeName = HashAlgorithmNames.Md5; ItemProperties.ItemMD5HashProgressVisibility = Visibility.Visible; ItemProperties.ItemMD5Hash = await App.CurrentInstance.InteractionOperations.GetHashForFile(selectedItem, hashAlgTypeName); ItemProperties.ItemMD5HashProgressVisibility = Visibility.Collapsed; ItemProperties.ItemMD5HashVisibility = Visibility.Visible; } else if (selectedItem.PrimaryItemAttribute == StorageItemTypes.Folder) { ItemProperties.ItemMD5HashVisibility = Visibility.Collapsed; ItemProperties.ItemMD5HashProgressVisibility = Visibility.Collapsed; } } else { var parentDirectory = App.CurrentInstance.ViewModel.CurrentFolder; if (parentDirectory.ItemPath.StartsWith(App.AppSettings.RecycleBinPath)) { // GetFolderFromPathAsync cannot access recyclebin folder // Currently a fake timestamp is used ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(parentDirectory.ItemDateModifiedReal); ItemProperties.ItemSize = parentDirectory.FileSize; } else { var parentDirectoryStorageItem = await StorageFolder.GetFolderFromPathAsync(parentDirectory.ItemPath); ItemProperties.ItemCreatedTimestamp = ListedItem.GetFriendlyDate(parentDirectoryStorageItem.DateCreated); } ItemProperties.ItemName = parentDirectory.ItemName; ItemProperties.ItemType = parentDirectory.ItemType; ItemProperties.ItemPath = parentDirectory.ItemPath; ItemProperties.LoadFileIcon = false; ItemProperties.LoadFolderGlyph = true; ItemProperties.LoadUnknownTypeGlyph = false; ItemProperties.ItemModifiedTimestamp = parentDirectory.ItemDateModified; ItemProperties.ItemMD5HashVisibility = Visibility.Collapsed; ItemProperties.ItemMD5HashProgressVisibility = Visibility.Collapsed; } }