Advertisement
Choubada

titlebar c#

May 14th, 2022
775
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public sealed partial class MainPage : Page
  2.     {
  3.         public MainPage()
  4.         {
  5.             this.InitializeComponent();
  6.            
  7.             var titleBar = ApplicationView.GetForCurrentView().TitleBar;
  8.  
  9.             titleBar.ButtonBackgroundColor = Colors.Transparent;
  10.             titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
  11.  
  12.             var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
  13.             coreTitleBar.ExtendViewIntoTitleBar = true;
  14.             UpdateTitleBarLayout(coreTitleBar);
  15.  
  16.             // Set XAML element as a draggable region.
  17.             Window.Current.SetTitleBar(AppTitleBar);
  18.  
  19.             coreTitleBar.LayoutMetricsChanged += CoreTitleBar_LayoutMetricsChanged;
  20.             coreTitleBar.IsVisibleChanged += CoreTitleBar_IsVisibleChanged;
  21.  
  22.             Window.Current.Activated += Current_Activated;
  23.         }
  24.        
  25.         private void CoreTitleBar_LayoutMetricsChanged(CoreApplicationViewTitleBar sender, object args)
  26.         {
  27.             UpdateTitleBarLayout(sender);
  28.         }
  29.  
  30.         private void UpdateTitleBarLayout(CoreApplicationViewTitleBar coreTitleBar)
  31.         {
  32.             // Update title bar control size as needed to account for system size changes.
  33.             AppTitleBar.Height = coreTitleBar.Height;
  34.  
  35.             // Ensure the custom title bar does not overlap window caption controls
  36.             Thickness currMargin = AppTitleBar.Margin;
  37.             AppTitleBar.Margin = new Thickness(currMargin.Left, currMargin.Top, coreTitleBar.SystemOverlayRightInset, currMargin.Bottom);
  38.         }
  39.  
  40.         private void CoreTitleBar_IsVisibleChanged(CoreApplicationViewTitleBar sender, object args)
  41.         {
  42.             if (sender.IsVisible)
  43.             {
  44.                 AppTitleBar.Visibility = Visibility.Visible;
  45.             }
  46.             else
  47.             {
  48.                 AppTitleBar.Visibility = Visibility.Collapsed;
  49.             }
  50.         }
  51.  
  52.         private void Current_Activated(object sender, Windows.UI.Core.WindowActivatedEventArgs e)
  53.         {
  54.             SolidColorBrush defaultForegroundBrush = (SolidColorBrush)Application.Current.Resources["TextFillColorPrimaryBrush"];
  55.             SolidColorBrush inactiveForegroundBrush = (SolidColorBrush)Application.Current.Resources["TextFillColorDisabledBrush"];
  56.  
  57.             if (e.WindowActivationState == Windows.UI.Core.CoreWindowActivationState.Deactivated)
  58.             {
  59.                 AppTitle.Foreground = inactiveForegroundBrush;
  60.             }
  61.             else
  62.             {
  63.                 AppTitle.Foreground = defaultForegroundBrush;
  64.             }
  65.         }
  66.  
  67.     }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement