Example #1
0
      private void _SetWindow(Window window)
      {
         Debug.Assert(null == _window);
         Debug.Assert(null != window);

         _window = window;
         _background = _window.Background;
         //if(_CaptionElement == null && !string.IsNullOrEmpty(CaptionElementName))
         //{
         //   if (!_window.IsLoaded)
         //   {
         //      _window.SourceInitialized +=
         //         (sender, e) => _CaptionElement = _window.FindName(CaptionElementName) as FrameworkElement;
         //   } else
         //   {
         //      _CaptionElement = _window.FindName(CaptionElementName) as FrameworkElement;
         //   }
         //}

         var resourceLocater = new Uri("/" + Assembly.GetExecutingAssembly().GetName().Name + ";component/ChromelessWindowTemplate.xaml", System.UriKind.Relative);
         _template = (ControlTemplate)Application.LoadComponent(resourceLocater);
         Debug.Assert(null != _template);

         _window.Template = _template;

         // Use whether we can get an HWND to determine if the Window has been loaded.
         _hwnd = new WindowInteropHelper(_window).Handle;

         if (IntPtr.Zero != _hwnd)
         {
            _window.ApplyTemplate();
            _HookCustomChrome();
         }
         else
         {
            _window.SourceInitialized += (sender, e) =>
            {
               _hwnd = new WindowInteropHelper(_window).Handle;
               Debug.Assert(IntPtr.Zero != _hwnd);
               _HookCustomChrome();
            };
         }
      }
        private void _SetWindow(Window window)
        {
            Assert.IsNull(_window);
            Assert.IsNotNull(window);

            _window = window;

            // There are potentially a couple funny states here.
            // The window may have been shown and closed, in which case it's no longer usable.
            // We shouldn't add any hooks in that case, just exit early.
            // If the window hasn't yet been shown, then we need to make sure to remove hooks after it's closed.
            _hwnd = new WindowInteropHelper(_window).Handle;

            if (Utility.IsPresentationFrameworkVersionLessThan4)
            {
                // On older versions of the framework the client size of the window is incorrectly calculated.
                // We need to modify the template to fix this on behalf of the user.
                Utility.AddDependencyPropertyChangeListener(_window, Window.TemplateProperty, _OnWindowPropertyChangedThatRequiresTemplateFixup);
                Utility.AddDependencyPropertyChangeListener(_window, Window.FlowDirectionProperty, _OnWindowPropertyChangedThatRequiresTemplateFixup);
            }

            _window.Closed += _UnsetWindow;

            // Use whether we can get an HWND to determine if the Window has been loaded.
            if (IntPtr.Zero != _hwnd)
            {
                // We've seen that the HwndSource can't always be retrieved from the HWND, so cache it early.
                // Specifically it seems to sometimes disappear when the OS theme is changing.
                _hwndSource = HwndSource.FromHwnd(_hwnd);
                Assert.IsNotNull(_hwndSource);
                _window.ApplyTemplate();

                if (_chromeInfo != null)
                {
                    _ApplyNewCustomChrome();
                }
            }
            else
            {
                _window.SourceInitialized += (sender, e) =>
                {
                    _hwnd = new WindowInteropHelper(_window).Handle;
                    Assert.IsNotDefault(_hwnd);
                    _hwndSource = HwndSource.FromHwnd(_hwnd);
                    Assert.IsNotNull(_hwndSource);

                    if (_chromeInfo != null)
                    {
                        _ApplyNewCustomChrome();
                    }
                };
            }
        }
Example #3
0
        private void _SetWindow(Window window)
        {
            Debug.Assert(null == _window);
            Debug.Assert(null != window);

            _window = window;

            var resourceLocater = new Uri("/" + Assembly.GetExecutingAssembly().GetName().Name + ";component/View/Chrome/ChromelessWindowTemplate.xaml", System.UriKind.Relative);
            _template = (ControlTemplate)Application.LoadComponent(resourceLocater);
            Debug.Assert(null != _template);

            _window.Template = _template;

            // Use whether we can get an HWND to determine if the Window has been loaded.
            _hwnd = new WindowInteropHelper(_window).Handle;

            if (IntPtr.Zero != _hwnd)
            {
                _window.ApplyTemplate();
                _HookCustomChrome();
            }
            else
            {
                _window.SourceInitialized += (sender, e) =>
                {
                    _hwnd = new WindowInteropHelper(_window).Handle;
                    Debug.Assert(IntPtr.Zero != _hwnd);
                    _HookCustomChrome();
                };
            }
        }