这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ IEnumerable<IDropArea> IOverlayWindowHost.GetDropAreas(LayoutFloatingWindowContr
if (_dropAreas != null) return _dropAreas;
_dropAreas = new List<IDropArea>();
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<LayoutAnchorablePaneControl>())
_dropAreas.Add(new DropArea<LayoutAnchorablePaneControl>(areaHost, DropAreaType.AnchorablePane));
foreach (var areaHost in rootVisual.FindVisualChildren<LayoutDocumentPaneControl>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public IEnumerable<IDropArea> GetDropAreas(LayoutFloatingWindowControl draggingW
}
}

var rootVisual = ((FloatingWindowContentHost)Content).RootVisual;
var rootVisual = ((FloatingWindowContentHost)Content).FindVisualTreeRoot();

foreach (var areaHost in rootVisual.FindVisualChildren<LayoutAnchorablePaneControl>())
_dropAreas.Add(new DropArea<LayoutAnchorablePaneControl>(areaHost, DropAreaType.AnchorablePane));
Expand Down
138 changes: 2 additions & 136 deletions source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

/// <summary><see cref="Content"/> dependency property. </summary>
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(nameof(Content), typeof(UIElement), typeof(FloatingWindowContentHost),
new FrameworkPropertyMetadata(null, OnContentChanged));

/// <summary>
/// Gets or sets the <see cref="Content"/> property. This dependency property
/// indicates ....
/// </summary>
public UIElement Content
{
get => (UIElement)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}

/// <summary>Handles changes to the <see cref="Content"/> property.</summary>
private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((FloatingWindowContentHost)d).OnContentChanged((UIElement)e.OldValue, (UIElement)e.NewValue);

/// <summary>Provides derived classes an opportunity to handle changes to the <see cref="Content"/> property.</summary>
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

/// <summary><see cref="SizeToContent"/> dependency property.</summary>
public static readonly DependencyProperty SizeToContentProperty = DependencyProperty.Register(nameof(SizeToContent), typeof(SizeToContent), typeof(FloatingWindowContentHost),
new FrameworkPropertyMetadata(SizeToContent.Manual, OnSizeToContentChanged));

/// <summary>Gets or sets the <see cref="SizeToContent"/> property.</summary>
public SizeToContent SizeToContent
{
get => (SizeToContent)GetValue(SizeToContentProperty);
set => SetValue(SizeToContentProperty, value);
}

/// <summary>Handles changes to the <see cref="SizeToContent"/> property.</summary>
private static void OnSizeToContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((FloatingWindowContentHost)d).OnSizeToContentChanged((SizeToContent)e.OldValue, (SizeToContent)e.NewValue);

/// <summary>Provides derived classes an opportunity to handle changes to the <see cref="SizeToContent"/> property.</summary>
protected virtual void OnSizeToContentChanged(SizeToContent oldValue, SizeToContent newValue)
{
if (_wpfContentHost != null) _wpfContentHost.SizeToContent = newValue;
}

#endregion SizeToContent

#endregion Properties

#region Overrides

/// <inheritdoc />
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);
}

/// <inheritdoc />
protected override void DestroyWindowCore(HandleRef hwnd)
{
_manager.InternalRemoveLogicalChild(_rootPresenter);
if (_wpfContentHost == null) return;
_wpfContentHost.Dispose();
_wpfContentHost = null;
}

/// <inheritdoc />
protected override Size MeasureOverride(Size constraint)
{
if (Content == null) return base.MeasureOverride(constraint);
Content.Measure(constraint);
return Content.DesiredSize;
}

#endregion Overrides

#region Methods

/// <summary>
/// Content_SizeChanged event handler.
/// </summary>
private void Content_SizeChanged(object sender, SizeChangedEventArgs e)
{
InvalidateMeasure();
InvalidateArrange();
}

#endregion Methods
}

#endregion Internal Classes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static void ActiveTheLastActivedContentOfPane(LayoutDocumentPane document
private static T GetLayoutControlByMousePosition<T>(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<T>())
{
Expand Down