diff --git a/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs index b9d6e0a4..efb281ab 100644 --- a/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs @@ -177,7 +177,7 @@ IEnumerable IOverlayWindowHost.GetDropAreas(LayoutFloatingWindowContr if (_dropAreas != null) return _dropAreas; _dropAreas = new List(); if (draggingWindow.Model is LayoutDocumentFloatingWindow) return _dropAreas; - var rootVisual = (Content as FloatingWindowContentHost).RootVisual; + var rootVisual = (Content as FloatingWindowContentHost).FindVisualTreeRoot(); foreach (var areaHost in rootVisual.FindVisualChildren()) _dropAreas.Add(new DropArea(areaHost, DropAreaType.AnchorablePane)); foreach (var areaHost in rootVisual.FindVisualChildren()) diff --git a/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs index e75d1aa6..b606dcab 100644 --- a/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs @@ -291,7 +291,7 @@ public IEnumerable GetDropAreas(LayoutFloatingWindowControl draggingW } } - var rootVisual = ((FloatingWindowContentHost)Content).RootVisual; + var rootVisual = ((FloatingWindowContentHost)Content).FindVisualTreeRoot(); foreach (var areaHost in rootVisual.FindVisualChildren()) _dropAreas.Add(new DropArea(areaHost, DropAreaType.AnchorablePane)); diff --git a/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs index f13ab5d6..6ce4e6e7 100644 --- a/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs @@ -516,7 +516,6 @@ protected override void OnClosed(EventArgs e) SizeChanged -= OnSizeChanged; if (Content != null) { - (Content as FloatingWindowContentHost)?.Dispose(); if (_hwndSrc != null) { _hwndSrc.RemoveHook(_hwndSrcHook); @@ -570,7 +569,7 @@ private static object CoerceContentValue(DependencyObject sender, object content { if (!(sender is LayoutFloatingWindowControl lfwc)) return null; if (lfwc.IsLoaded && lfwc.IsContentImmutable) return lfwc.Content; - return new FloatingWindowContentHost((LayoutFloatingWindowControl)sender) { Content = content as UIElement }; + return new FloatingWindowContentHost(/*(LayoutFloatingWindowControl)sender*/) { Content = content as UIElement }; } private void OnLoaded(object sender, RoutedEventArgs e) @@ -711,141 +710,8 @@ public virtual void DisableBindings() #region Internal Classes - protected internal class FloatingWindowContentHost : HwndHost + protected internal class FloatingWindowContentHost : ContentControl { - #region fields - - private readonly LayoutFloatingWindowControl _owner; - private HwndSource _wpfContentHost = null; - private Border _rootPresenter = null; - private DockingManager _manager = null; - - #endregion fields - - #region Constructors - - public FloatingWindowContentHost(LayoutFloatingWindowControl owner) - { - _owner = owner; - var binding = new Binding(nameof(SizeToContent)) { Source = _owner }; - BindingOperations.SetBinding(this, SizeToContentProperty, binding); - } - - #endregion Constructors - - #region Properties - - public Visual RootVisual => _rootPresenter; - - #region Content - - /// dependency property. - public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(nameof(Content), typeof(UIElement), typeof(FloatingWindowContentHost), - new FrameworkPropertyMetadata(null, OnContentChanged)); - - /// - /// Gets or sets the property. This dependency property - /// indicates .... - /// - public UIElement Content - { - get => (UIElement)GetValue(ContentProperty); - set => SetValue(ContentProperty, value); - } - - /// Handles changes to the property. - private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((FloatingWindowContentHost)d).OnContentChanged((UIElement)e.OldValue, (UIElement)e.NewValue); - - /// Provides derived classes an opportunity to handle changes to the property. - protected virtual void OnContentChanged(UIElement oldValue, UIElement newValue) - { - if (_rootPresenter != null) _rootPresenter.Child = Content; - if (oldValue is FrameworkElement oldContent) oldContent.SizeChanged -= Content_SizeChanged; - if (newValue is FrameworkElement newContent) newContent.SizeChanged += Content_SizeChanged; - } - - #endregion Content - - #region SizeToContent - - /// dependency property. - public static readonly DependencyProperty SizeToContentProperty = DependencyProperty.Register(nameof(SizeToContent), typeof(SizeToContent), typeof(FloatingWindowContentHost), - new FrameworkPropertyMetadata(SizeToContent.Manual, OnSizeToContentChanged)); - - /// Gets or sets the property. - public SizeToContent SizeToContent - { - get => (SizeToContent)GetValue(SizeToContentProperty); - set => SetValue(SizeToContentProperty, value); - } - - /// Handles changes to the property. - private static void OnSizeToContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((FloatingWindowContentHost)d).OnSizeToContentChanged((SizeToContent)e.OldValue, (SizeToContent)e.NewValue); - - /// Provides derived classes an opportunity to handle changes to the property. - protected virtual void OnSizeToContentChanged(SizeToContent oldValue, SizeToContent newValue) - { - if (_wpfContentHost != null) _wpfContentHost.SizeToContent = newValue; - } - - #endregion SizeToContent - - #endregion Properties - - #region Overrides - - /// - protected override HandleRef BuildWindowCore(HandleRef hwndParent) - { - _wpfContentHost = new HwndSource(new HwndSourceParameters - { - ParentWindow = hwndParent.Handle, - WindowStyle = Win32Helper.WS_CHILD | Win32Helper.WS_VISIBLE | Win32Helper.WS_CLIPSIBLINGS | Win32Helper.WS_CLIPCHILDREN, - Width = 1, - Height = 1, - UsesPerPixelOpacity = true, - }); - - _rootPresenter = new Border { Child = new AdornerDecorator { Child = Content }, Focusable = true }; - AutomationProperties.SetName(_rootPresenter, "FloatingWindowHost"); - _rootPresenter.SetBinding(Border.BackgroundProperty, new Binding(nameof(Background)) { Source = _owner }); - _wpfContentHost.RootVisual = _rootPresenter; - _manager = _owner.Model.Root.Manager; - _manager.InternalAddLogicalChild(_rootPresenter); - return new HandleRef(this, _wpfContentHost.Handle); - } - - /// - protected override void DestroyWindowCore(HandleRef hwnd) - { - _manager.InternalRemoveLogicalChild(_rootPresenter); - if (_wpfContentHost == null) return; - _wpfContentHost.Dispose(); - _wpfContentHost = null; - } - - /// - protected override Size MeasureOverride(Size constraint) - { - if (Content == null) return base.MeasureOverride(constraint); - Content.Measure(constraint); - return Content.DesiredSize; - } - - #endregion Overrides - - #region Methods - - /// - /// Content_SizeChanged event handler. - /// - private void Content_SizeChanged(object sender, SizeChangedEventArgs e) - { - InvalidateMeasure(); - InvalidateArrange(); - } - - #endregion Methods } #endregion Internal Classes diff --git a/source/Components/AvalonDock/Controls/LayoutFloatingWindowControlHelper.cs b/source/Components/AvalonDock/Controls/LayoutFloatingWindowControlHelper.cs index ca2a0c0c..a51baee2 100644 --- a/source/Components/AvalonDock/Controls/LayoutFloatingWindowControlHelper.cs +++ b/source/Components/AvalonDock/Controls/LayoutFloatingWindowControlHelper.cs @@ -130,7 +130,7 @@ public static void ActiveTheLastActivedContentOfPane(LayoutDocumentPane document private static T GetLayoutControlByMousePosition(LayoutFloatingWindowControl fwc) where T : FrameworkElement, ILayoutControl { var mousePosition = fwc.PointToScreenDPI(Mouse.GetPosition(fwc)); - var rootVisual = ((LayoutFloatingWindowControl.FloatingWindowContentHost)fwc.Content).RootVisual; + var rootVisual = ((LayoutFloatingWindowControl.FloatingWindowContentHost)fwc.Content).FindVisualTreeRoot(); foreach (var areaHost in rootVisual.FindVisualChildren()) {