private void UpdateIsCaptionBarHeight()
        {
            var chrome = ShellChrome.GetWindowChrome(this);

            if (chrome == null)
            {
                return;
            }

            var captionBar = this._captionBar;

            if (captionBar != null)
            {
                if (this.SystemDpi.Y > 0)
                {
                    chrome.CaptionHeight = captionBar.ActualHeight * this.DpiScaleTransform.Value.M22;
                }
                else
                {
                    chrome.CaptionHeight = captionBar.ActualHeight;
                }
            }
            else
            {
                chrome.CaptionHeight = 0;
            }
        }
        private static void IsCaptionBarChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var instance = d as FrameworkElement;

            if (instance == null)
            {
                return;
            }

            var window = GetWindow(instance) as MetroWindow;

            if (window == null)
            {
                return;
            }

            window.captionBar = (bool)e.NewValue ? instance : null;

            instance.Loaded += (sender, args) =>
            {
                var chrome = ShellChrome.GetWindowChrome(window);
                if (chrome != null)
                {
                    chrome.CaptionHeight = instance.ActualHeight;
                }
            };
        }
        public MainWindow()
        {
            //Get Existing 'WindowChrome' Properties.
            var captionHeight = chrome.CaptionHeight;

            //Set Existing 'WindowChrome' Properties.
            chrome.GlassFrameThickness = new Thickness(2d);
            //Assign a New 'WindowChrome'.
            chrome = new System.Windows.Shell.WindowChrome();
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            this._resizeGrip = this.GetTemplateChild(PART_ResizeGrip) as FrameworkElement;
            if (this._resizeGrip != null)
            {
                this._resizeGrip.Visibility = this.ResizeMode == ResizeMode.CanResizeWithGrip
                                        ? Visibility.Visible
                                        : Visibility.Collapsed;

                ShellChrome.SetIsHitTestVisibleInChrome(this._resizeGrip, true);
            }
        }