From 05693836dff53811b95b1e865579f77f8cdf4c5a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=88=98=E6=99=93=E9=9D=92?= <569132102@qq.com>
Date: Sat, 4 Jul 2020 11:03:26 +0800
Subject: [PATCH 1/5] #174 Migrating AutoWindowSizeWhenOpened to DockingManager
---
.../Controls/LayoutFloatingWindowControl.cs | 1203 ++++++++---------
.../Components/AvalonDock/DockingManager.cs | 19 +
source/TestApp/App.xaml | 2 +-
source/TestApp/MainWindow.xaml | 1 +
4 files changed, 609 insertions(+), 616 deletions(-)
diff --git a/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs
index 74e48082..e2d538c2 100644
--- a/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs
+++ b/source/Components/AvalonDock/Controls/LayoutFloatingWindowControl.cs
@@ -23,172 +23,172 @@ This program is provided to you under the terms of the Microsoft Public
namespace AvalonDock.Controls
{
- ///
- ///
- ///
- /// Implements an abstraction layer for floating windows that can host other controls
- /// (eg. documents and/or ).
- ///
- /// A floating window can be dragged around independently of the .
- ///
- ///
- ///
- public abstract class LayoutFloatingWindowControl : Window, ILayoutControl
- {
- #region fields
- private ResourceDictionary currentThemeResourceDictionary; // = null
- private bool _isInternalChange; //false
- private readonly ILayoutElement _model;
- private bool _attachDrag = false;
- private HwndSource _hwndSrc;
- private HwndSourceHook _hwndSrcHook;
- private DragService _dragService = null;
- private bool _internalCloseFlag = false;
- private bool _isClosing = false;
-
- ///
- /// Is false until the margins have been found once.
- ///
- ///
+ ///
+ ///
+ ///
+ /// Implements an abstraction layer for floating windows that can host other controls
+ /// (eg. documents and/or ).
+ ///
+ /// A floating window can be dragged around independently of the .
+ ///
+ ///
+ ///
+ public abstract class LayoutFloatingWindowControl : Window, ILayoutControl
+ {
+ #region fields
+ private ResourceDictionary currentThemeResourceDictionary; // = null
+ private bool _isInternalChange; //false
+ private readonly ILayoutElement _model;
+ private bool _attachDrag = false;
+ private HwndSource _hwndSrc;
+ private HwndSourceHook _hwndSrcHook;
+ private DragService _dragService = null;
+ private bool _internalCloseFlag = false;
+ private bool _isClosing = false;
+
+ ///
+ /// Is false until the margins have been found once.
+ ///
+ ///
private bool _isTotalMarginSet = false;
#endregion fields
- #region Constructors
-
- static LayoutFloatingWindowControl()
- {
- AllowsTransparencyProperty.OverrideMetadata(typeof(LayoutFloatingWindowControl), new FrameworkPropertyMetadata(false));
- ContentProperty.OverrideMetadata(typeof(LayoutFloatingWindowControl), new FrameworkPropertyMetadata(null, null, CoerceContentValue));
- ShowInTaskbarProperty.OverrideMetadata(typeof(LayoutFloatingWindowControl), new FrameworkPropertyMetadata(false));
- WindowStyleProperty.OverrideMetadata(typeof(LayoutFloatingWindowControl), new FrameworkPropertyMetadata(WindowStyle.None));
- }
-
- protected LayoutFloatingWindowControl(ILayoutElement model)
- {
- Loaded += OnLoaded;
- Unloaded += OnUnloaded;
- Closing += OnClosing;
- SizeChanged += OnSizeChanged;
- _model = model;
- }
-
- protected LayoutFloatingWindowControl(ILayoutElement model, bool isContentImmutable)
- : this(model)
- {
- IsContentImmutable = isContentImmutable;
- }
-
- #endregion Constructors
-
- #region Properties
- ///
- /// Gets/Sets the X,Y delta between the element being dragged and the
- /// mouse position. The value of this property is used during the drag
- /// cycle to position the dragged item under the mouse pointer.
- ///
- /// Set this property on initialization to ensure that
- /// the delta between mouse and control being dragged
- /// remains constant.
- ///
- internal Point DragDelta { get; set; }
-
- public abstract ILayoutElement Model { get; }
-
- #region IsContentImmutable
-
- /// dependency property.
- public static readonly DependencyProperty IsContentImmutableProperty = DependencyProperty.Register(nameof(IsContentImmutable), typeof(bool), typeof(LayoutFloatingWindowControl),
- new FrameworkPropertyMetadata(false));
-
- ///
- /// Gets/sets the property. This dependency property
- /// indicates if the content can be modified.
- ///
- public bool IsContentImmutable
- {
- get => (bool)GetValue(IsContentImmutableProperty);
- private set => SetValue(IsContentImmutableProperty, value);
- }
-
- #endregion IsContentImmutable
-
- #region IsDragging
-
- /// Read-Only dependency property.
- private static readonly DependencyPropertyKey IsDraggingPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsDragging), typeof(bool), typeof(LayoutFloatingWindowControl),
- new FrameworkPropertyMetadata(false, OnIsDraggingChanged));
-
- public static readonly DependencyProperty IsDraggingProperty = IsDraggingPropertyKey.DependencyProperty;
-
- ///
- /// Gets the property. This dependency property
- /// indicates that this floating window is being dragged.
- ///
- public bool IsDragging => (bool)GetValue(IsDraggingProperty);
-
- ///
- /// Provides a secure method for setting the property.
- /// This dependency property indicates that this floating window is being dragged.
- ///
- /// The new value for the property.
- protected void SetIsDragging(bool value) => SetValue(IsDraggingPropertyKey, value);
-
- /// Handles changes to the property.
- private static void OnIsDraggingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((LayoutFloatingWindowControl)d).OnIsDraggingChanged(e);
-
- /// Provides derived classes an opportunity to handle changes to the property.
- protected virtual void OnIsDraggingChanged(DependencyPropertyChangedEventArgs e)
- {
- if ((bool) e.NewValue)
- CaptureMouse();
- else
- ReleaseMouseCapture();
- }
-
- #endregion IsDragging
-
- #region CloseInitiatedByUser
-
- protected bool CloseInitiatedByUser => !_internalCloseFlag;
-
- #endregion CloseInitiatedByUser
-
- internal bool KeepContentVisibleOnClose { get; set; }
-
- #region IsMaximized
-
- /// dependency property.
- public static readonly DependencyProperty IsMaximizedProperty = DependencyProperty.Register(nameof(IsMaximized), typeof(bool), typeof(LayoutFloatingWindowControl),
- new FrameworkPropertyMetadata(false));
-
- /// Gets/sets the property. This dependency property indicates if the window is maximized.
- /// Provides a secure method for setting the property.
- public bool IsMaximized
- {
- get => (bool)GetValue(IsMaximizedProperty);
- private set
- {
- SetValue(IsMaximizedProperty, value);
- UpdatePositionAndSizeOfPanes();
- }
- }
-
- ///
- protected override void OnStateChanged(EventArgs e)
- {
- if (!_isInternalChange)
- UpdateMaximizedState(WindowState == WindowState.Maximized);
-
- base.OnStateChanged(e);
- }
-
- #endregion IsMaximized
+ #region Constructors
+
+ static LayoutFloatingWindowControl()
+ {
+ AllowsTransparencyProperty.OverrideMetadata(typeof(LayoutFloatingWindowControl), new FrameworkPropertyMetadata(false));
+ ContentProperty.OverrideMetadata(typeof(LayoutFloatingWindowControl), new FrameworkPropertyMetadata(null, null, CoerceContentValue));
+ ShowInTaskbarProperty.OverrideMetadata(typeof(LayoutFloatingWindowControl), new FrameworkPropertyMetadata(false));
+ WindowStyleProperty.OverrideMetadata(typeof(LayoutFloatingWindowControl), new FrameworkPropertyMetadata(WindowStyle.None));
+ }
+
+ protected LayoutFloatingWindowControl(ILayoutElement model)
+ {
+ Loaded += OnLoaded;
+ Unloaded += OnUnloaded;
+ Closing += OnClosing;
+ SizeChanged += OnSizeChanged;
+ _model = model;
+ }
+
+ protected LayoutFloatingWindowControl(ILayoutElement model, bool isContentImmutable)
+ : this(model)
+ {
+ IsContentImmutable = isContentImmutable;
+ }
+
+ #endregion Constructors
+
+ #region Properties
+ ///
+ /// Gets/Sets the X,Y delta between the element being dragged and the
+ /// mouse position. The value of this property is used during the drag
+ /// cycle to position the dragged item under the mouse pointer.
+ ///
+ /// Set this property on initialization to ensure that
+ /// the delta between mouse and control being dragged
+ /// remains constant.
+ ///
+ internal Point DragDelta { get; set; }
+
+ public abstract ILayoutElement Model { get; }
+
+ #region IsContentImmutable
+
+ /// dependency property.
+ public static readonly DependencyProperty IsContentImmutableProperty = DependencyProperty.Register(nameof(IsContentImmutable), typeof(bool), typeof(LayoutFloatingWindowControl),
+ new FrameworkPropertyMetadata(false));
+
+ ///
+ /// Gets/sets the property. This dependency property
+ /// indicates if the content can be modified.
+ ///
+ public bool IsContentImmutable
+ {
+ get => (bool)GetValue(IsContentImmutableProperty);
+ private set => SetValue(IsContentImmutableProperty, value);
+ }
+
+ #endregion IsContentImmutable
+
+ #region IsDragging
+
+ /// Read-Only dependency property.
+ private static readonly DependencyPropertyKey IsDraggingPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsDragging), typeof(bool), typeof(LayoutFloatingWindowControl),
+ new FrameworkPropertyMetadata(false, OnIsDraggingChanged));
+
+ public static readonly DependencyProperty IsDraggingProperty = IsDraggingPropertyKey.DependencyProperty;
+
+ ///
+ /// Gets the property. This dependency property
+ /// indicates that this floating window is being dragged.
+ ///
+ public bool IsDragging => (bool)GetValue(IsDraggingProperty);
+
+ ///
+ /// Provides a secure method for setting the property.
+ /// This dependency property indicates that this floating window is being dragged.
+ ///
+ /// The new value for the property.
+ protected void SetIsDragging(bool value) => SetValue(IsDraggingPropertyKey, value);
+
+ /// Handles changes to the property.
+ private static void OnIsDraggingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((LayoutFloatingWindowControl)d).OnIsDraggingChanged(e);
+
+ /// Provides derived classes an opportunity to handle changes to the property.
+ protected virtual void OnIsDraggingChanged(DependencyPropertyChangedEventArgs e)
+ {
+ if ((bool)e.NewValue)
+ CaptureMouse();
+ else
+ ReleaseMouseCapture();
+ }
+
+ #endregion IsDragging
+
+ #region CloseInitiatedByUser
+
+ protected bool CloseInitiatedByUser => !_internalCloseFlag;
+
+ #endregion CloseInitiatedByUser
+
+ internal bool KeepContentVisibleOnClose { get; set; }
+
+ #region IsMaximized
+
+ /// dependency property.
+ public static readonly DependencyProperty IsMaximizedProperty = DependencyProperty.Register(nameof(IsMaximized), typeof(bool), typeof(LayoutFloatingWindowControl),
+ new FrameworkPropertyMetadata(false));
+
+ /// Gets/sets the property. This dependency property indicates if the window is maximized.
+ /// Provides a secure method for setting the property.
+ public bool IsMaximized
+ {
+ get => (bool)GetValue(IsMaximizedProperty);
+ private set
+ {
+ SetValue(IsMaximizedProperty, value);
+ UpdatePositionAndSizeOfPanes();
+ }
+ }
+
+ ///
+ protected override void OnStateChanged(EventArgs e)
+ {
+ if (!_isInternalChange)
+ UpdateMaximizedState(WindowState == WindowState.Maximized);
+
+ base.OnStateChanged(e);
+ }
+
+ #endregion IsMaximized
#region TotalMargin
- private static readonly DependencyPropertyKey TotalMarginPropertyKey =
+ private static readonly DependencyPropertyKey TotalMarginPropertyKey =
DependencyProperty.RegisterReadOnly(nameof(TotalMargin),
- typeof(Thickness),
+ typeof(Thickness),
typeof(LayoutFloatingWindowControl),
new FrameworkPropertyMetadata(default(Thickness)));
@@ -200,186 +200,159 @@ protected override void OnStateChanged(EventArgs e)
/// The margin is queried from the visual tree the first time it is rendered, zero until the first call of FilterMessage(WM_ACTIVATE)
///
public Thickness TotalMargin
- {
- get { return (Thickness) GetValue(TotalMarginProperty); }
+ {
+ get { return (Thickness)GetValue(TotalMarginProperty); }
protected set { SetValue(TotalMarginPropertyKey, value); }
}
- #endregion
+ #endregion
- #region ContentMinHeight
- public static readonly DependencyPropertyKey ContentMinHeightPropertyKey = DependencyProperty.RegisterReadOnly(
+ #region ContentMinHeight
+ public static readonly DependencyPropertyKey ContentMinHeightPropertyKey = DependencyProperty.RegisterReadOnly(
nameof(ContentMinHeight), typeof(double), typeof(LayoutFloatingWindowControl), new FrameworkPropertyMetadata(0.0));
public static readonly DependencyProperty ContentMinHeightProperty =
ContentMinHeightPropertyKey.DependencyProperty;
- ///
- /// The MinHeight of the content of the window, will be 0 until the window has been rendered, or if the MinHeight is unset for the content
- ///
- public double ContentMinHeight
+ ///
+ /// The MinHeight of the content of the window, will be 0 until the window has been rendered, or if the MinHeight is unset for the content
+ ///
+ public double ContentMinHeight
{
- get { return (double) GetValue(ContentMinHeightProperty); }
+ get { return (double)GetValue(ContentMinHeightProperty); }
set { SetValue(ContentMinHeightPropertyKey, value); }
}
- #endregion
+ #endregion
- #region ContentMinWidth
- public static readonly DependencyPropertyKey ContentMinWidthPropertyKey = DependencyProperty.RegisterReadOnly(
+ #region ContentMinWidth
+ public static readonly DependencyPropertyKey ContentMinWidthPropertyKey = DependencyProperty.RegisterReadOnly(
nameof(ContentMinWidth), typeof(double), typeof(LayoutFloatingWindowControl), new FrameworkPropertyMetadata(0.0));
public static readonly DependencyProperty ContentMinWidthProperty =
ContentMinWidthPropertyKey.DependencyProperty;
- ///
- /// The MinWidth ocf the content of the window, will be 0 until the window has been rendered, or if the MinWidth is unset for the content
- ///
- public double ContentMinWidth
+ ///
+ /// The MinWidth ocf the content of the window, will be 0 until the window has been rendered, or if the MinWidth is unset for the content
+ ///
+ public double ContentMinWidth
{
- get { return (double) GetValue(ContentMinWidthProperty); }
+ get { return (double)GetValue(ContentMinWidthProperty); }
set { SetValue(ContentMinWidthPropertyKey, value); }
}
- #endregion
+ #endregion
- #region SetWindowSizeWhenOpened
+ #endregion Properties
- public static readonly DependencyProperty SetWindowSizeWhenOpenedProperty = DependencyProperty.Register(
- nameof(SetWindowSizeWhenOpened), typeof(bool), typeof(LayoutFloatingWindowControl), new PropertyMetadata(false,
- (sender, args) =>
+ #region Internal Methods
+
+ internal virtual void UpdateThemeResources(Theme oldTheme = null)
+ {
+ if (oldTheme != null)
+ {
+ if (oldTheme is DictionaryTheme)
{
- if (args.OldValue != args.NewValue &&
- sender is LayoutFloatingWindowControl control)
+ if (currentThemeResourceDictionary != null)
{
- // This will resize the window when this property is set to true and the window is open
- control._isTotalMarginSet = false;
+ Resources.MergedDictionaries.Remove(currentThemeResourceDictionary);
+ currentThemeResourceDictionary = null;
}
- }));
-
- ///
- /// If true the MinHeight and MinWidth of the content will be used together with the margins to determine the initial size of the floating window
- ///
- ///
- ///
- ///
- public bool SetWindowSizeWhenOpened
+ }
+ else
+ {
+ var resourceDictionaryToRemove =
+ Resources.MergedDictionaries.FirstOrDefault(r => r.Source == oldTheme.GetResourceUri());
+ if (resourceDictionaryToRemove != null)
+ Resources.MergedDictionaries.Remove(
+ resourceDictionaryToRemove);
+ }
+ }
+
+ var manager = _model.Root?.Manager;
+ if (manager?.Theme == null) return;
+ if (manager.Theme is DictionaryTheme dictionaryTheme)
+ {
+ currentThemeResourceDictionary = dictionaryTheme.ThemeResourceDictionary;
+ Resources.MergedDictionaries.Add(currentThemeResourceDictionary);
+ }
+ else
+ Resources.MergedDictionaries.Add(new ResourceDictionary { Source = manager.Theme.GetResourceUri() });
+ }
+
+ internal void AttachDrag(bool onActivated = true)
{
- get { return (bool) GetValue(SetWindowSizeWhenOpenedProperty); }
- set { SetValue(SetWindowSizeWhenOpenedProperty, value); }
+ if (onActivated)
+ {
+ _attachDrag = true;
+ Activated += OnActivated;
+ }
+ else
+ {
+ var windowHandle = new WindowInteropHelper(this).Handle;
+ var lParam = new IntPtr(((int)Left & 0xFFFF) | ((int)Top << 16));
+ Win32Helper.SendMessage(windowHandle, Win32Helper.WM_NCLBUTTONDOWN, new IntPtr(Win32Helper.HT_CAPTION), lParam);
+ }
}
- #endregion
- #endregion Properties
-
- #region Internal Methods
-
- internal virtual void UpdateThemeResources(Theme oldTheme = null)
- {
- if (oldTheme != null)
- {
- if (oldTheme is DictionaryTheme)
- {
- if (currentThemeResourceDictionary != null)
- {
- Resources.MergedDictionaries.Remove(currentThemeResourceDictionary);
- currentThemeResourceDictionary = null;
- }
- }
- else
- {
- var resourceDictionaryToRemove =
- Resources.MergedDictionaries.FirstOrDefault(r => r.Source == oldTheme.GetResourceUri());
- if (resourceDictionaryToRemove != null)
- Resources.MergedDictionaries.Remove(
- resourceDictionaryToRemove);
- }
- }
-
- var manager = _model.Root?.Manager;
- if (manager?.Theme == null) return;
- if (manager.Theme is DictionaryTheme dictionaryTheme)
- {
- currentThemeResourceDictionary = dictionaryTheme.ThemeResourceDictionary;
- Resources.MergedDictionaries.Add(currentThemeResourceDictionary);
- }
- else
- Resources.MergedDictionaries.Add(new ResourceDictionary {Source = manager.Theme.GetResourceUri()});
- }
-
- internal void AttachDrag(bool onActivated = true)
- {
- if (onActivated)
- {
- _attachDrag = true;
- Activated += OnActivated;
- }
- else
- {
- var windowHandle = new WindowInteropHelper(this).Handle;
- var lParam = new IntPtr(((int)Left & 0xFFFF) | ((int)Top << 16));
- Win32Helper.SendMessage(windowHandle, Win32Helper.WM_NCLBUTTONDOWN, new IntPtr(Win32Helper.HT_CAPTION), lParam);
- }
- }
-
- protected virtual IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
- {
- handled = false;
-
- switch (msg)
- {
- case Win32Helper.WM_ACTIVATE:
- if (((int)wParam & 0xFFFF) == Win32Helper.WA_INACTIVE)
- {
- if (lParam == this.GetParentWindowHandle())
- {
- Win32Helper.SetActiveWindow(_hwndSrc.Handle);
- handled = true;
- }
- }
+ protected virtual IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
+ {
+ handled = false;
+
+ switch (msg)
+ {
+ case Win32Helper.WM_ACTIVATE:
+ if (((int)wParam & 0xFFFF) == Win32Helper.WA_INACTIVE)
+ {
+ if (lParam == this.GetParentWindowHandle())
+ {
+ Win32Helper.SetActiveWindow(_hwndSrc.Handle);
+ handled = true;
+ }
+ }
UpdateWindowsSizeBasedOnMinSize();
break;
- case Win32Helper.WM_EXITSIZEMOVE:
- UpdatePositionAndSizeOfPanes();
-
- if (_dragService != null)
- {
- var mousePosition = this.TransformToDeviceDPI(Win32Helper.GetMousePosition());
- _dragService.Drop(mousePosition, out var dropFlag);
- _dragService = null;
- SetIsDragging(false);
- if (dropFlag) InternalClose();
- }
- break;
- case Win32Helper.WM_MOVING:
- {
- UpdateDragPosition();
- if (IsMaximized) UpdateMaximizedState(false);
- }
- break;
- case Win32Helper.WM_LBUTTONUP: //set as handled right button click on title area (after showing context menu)
- if (_dragService != null && Mouse.LeftButton == MouseButtonState.Released)
- {
- _dragService.Abort();
- _dragService = null;
- SetIsDragging(false);
- }
- break;
- case Win32Helper.WM_SYSCOMMAND:
- var command = (int)wParam & 0xFFF0;
- if (command == Win32Helper.SC_MAXIMIZE || command == Win32Helper.SC_RESTORE) UpdateMaximizedState(command == Win32Helper.SC_MAXIMIZE);
- break;
- }
- return IntPtr.Zero;
- }
-
- ///
- /// Set the margins of the window control (including the borders of the floating window and the title bar).
- /// The result will be stored in _totalMargin
.
- ///
- /// If the control is not loaded _totalMargin
will not be set.
- private void UpdateMargins()
+ case Win32Helper.WM_EXITSIZEMOVE:
+ UpdatePositionAndSizeOfPanes();
+
+ if (_dragService != null)
+ {
+ var mousePosition = this.TransformToDeviceDPI(Win32Helper.GetMousePosition());
+ _dragService.Drop(mousePosition, out var dropFlag);
+ _dragService = null;
+ SetIsDragging(false);
+ if (dropFlag) InternalClose();
+ }
+ break;
+ case Win32Helper.WM_MOVING:
+ {
+ UpdateDragPosition();
+ if (IsMaximized) UpdateMaximizedState(false);
+ }
+ break;
+ case Win32Helper.WM_LBUTTONUP: //set as handled right button click on title area (after showing context menu)
+ if (_dragService != null && Mouse.LeftButton == MouseButtonState.Released)
+ {
+ _dragService.Abort();
+ _dragService = null;
+ SetIsDragging(false);
+ }
+ break;
+ case Win32Helper.WM_SYSCOMMAND:
+ var command = (int)wParam & 0xFFF0;
+ if (command == Win32Helper.SC_MAXIMIZE || command == Win32Helper.SC_RESTORE) UpdateMaximizedState(command == Win32Helper.SC_MAXIMIZE);
+ break;
+ }
+ return IntPtr.Zero;
+ }
+
+ ///
+ /// Set the margins of the window control (including the borders of the floating window and the title bar).
+ /// The result will be stored in _totalMargin
.
+ ///
+ /// If the control is not loaded _totalMargin
will not be set.
+ private void UpdateMargins()
{
- // The grid with window bar and content
+ // The grid with window bar and content
var grid = this.GetChildrenRecursive()
.OfType()
.FirstOrDefault(g => g.RowDefinitions.Count > 0);
@@ -389,15 +362,15 @@ private void UpdateMargins()
if (contentControl == null)
return;
// The content control in the grid, this has a different tree to walk up
- var layoutContent = (LayoutContent)contentControl.Content;
- if (grid != null && layoutContent.Content is FrameworkElement content)
+ var layoutContent = (LayoutContent)contentControl.Content;
+ if (grid != null && layoutContent.Content is FrameworkElement content)
{
var parents = content.GetParents().ToArray();
var children = this.GetChildrenRecursive()
.TakeWhile(c => c != grid)
.ToArray();
- var borders = children
- .OfType()
+ var borders = children
+ .OfType()
.Concat(parents
.OfType())
.ToArray();
@@ -411,7 +384,7 @@ private void UpdateMargins()
.Concat(parents
.OfType())
.ToArray();
- var padding = controls.Sum(b => b.Padding);
+ var padding = controls.Sum(b => b.Padding);
var border = borders.Sum(b => b.BorderThickness);
var margin = frameworkElements.Sum(f => f.Margin);
margin = margin.Add(padding).Add(border).Add(grid.Margin);
@@ -421,30 +394,30 @@ private void UpdateMargins()
}
}
- ///
- /// Update the floating window size based on the MinHeight
and MinWidth
of the content of the control.
- ///
- /// This will only be run once, when the window is rendered the first time and _totalMargin
is identified.
- private void UpdateWindowsSizeBasedOnMinSize()
+ ///
+ /// Update the floating window size based on the MinHeight
and MinWidth
of the content of the control.
+ ///
+ /// This will only be run once, when the window is rendered the first time and _totalMargin
is identified.
+ private void UpdateWindowsSizeBasedOnMinSize()
{
if (!_isTotalMarginSet)
{
UpdateMargins();
- if(_isTotalMarginSet)
+ if (_isTotalMarginSet)
{
- // The LayoutAnchorableControl is bound via the ContentPresenter, hence it is best to do below in code and not in a style
- // See https://github.com/Dirkster99/AvalonDock/pull/146#issuecomment-609974424
- var layoutContents = this.GetChildrenRecursive()
+ // The LayoutAnchorableControl is bound via the ContentPresenter, hence it is best to do below in code and not in a style
+ // See https://github.com/Dirkster99/AvalonDock/pull/146#issuecomment-609974424
+ var layoutContents = this.GetChildrenRecursive()
.OfType()
.Select(c => c.Content)
.OfType()
.Select(lc => lc.Content);
- var contents = layoutContents.OfType();
+ var contents = layoutContents.OfType();
foreach (var content in contents)
{
ContentMinHeight = Math.Max(content.MinHeight, ContentMinHeight);
ContentMinWidth = Math.Max(content.MinWidth, ContentMinWidth);
- if (SetWindowSizeWhenOpened)
+ if ((this.Model?.Root?.Manager?.AutoWindowSizeWhenOpened).GetValueOrDefault())
{
var parent = content.GetParents()
.OfType()
@@ -468,297 +441,297 @@ private void UpdateWindowsSizeBasedOnMinSize()
}
internal void InternalClose(bool closeInitiatedByUser = false)
- {
- _internalCloseFlag = !closeInitiatedByUser;
- if (_isClosing) return;
- _isClosing = true;
- Close();
- }
-
- #endregion Internal Methods
-
- #region Overrides
-
- ///
- protected override void OnClosed(EventArgs e)
- {
- SizeChanged -= OnSizeChanged;
- if (Content != null)
- {
- (Content as FloatingWindowContentHost)?.Dispose();
- if (_hwndSrc != null)
- {
- _hwndSrc.RemoveHook(_hwndSrcHook);
- _hwndSrc.Dispose();
- _hwndSrc = null;
- }
- }
- base.OnClosed(e);
- }
-
- ///
- protected override void OnInitialized(EventArgs e)
- {
- CommandBindings.Add(new CommandBinding(Microsoft.Windows.Shell.SystemCommands.CloseWindowCommand,
- (s, args) => Microsoft.Windows.Shell.SystemCommands.CloseWindow((Window)args.Parameter)));
- CommandBindings.Add(new CommandBinding(Microsoft.Windows.Shell.SystemCommands.MaximizeWindowCommand,
- (s, args) => Microsoft.Windows.Shell.SystemCommands.MaximizeWindow((Window)args.Parameter)));
- CommandBindings.Add(new CommandBinding(Microsoft.Windows.Shell.SystemCommands.MinimizeWindowCommand,
- (s, args) => Microsoft.Windows.Shell.SystemCommands.MinimizeWindow((Window)args.Parameter)));
- CommandBindings.Add(new CommandBinding(Microsoft.Windows.Shell.SystemCommands.RestoreWindowCommand,
- (s, args) => Microsoft.Windows.Shell.SystemCommands.RestoreWindow((Window)args.Parameter)));
- //Debug.Assert(this.Owner != null);
- base.OnInitialized(e);
- }
-
- #endregion Overrides
-
- #region Private Methods
-
- 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 };
- }
-
- private void OnLoaded(object sender, RoutedEventArgs e)
- {
- Loaded -= OnLoaded;
- this.SetParentToMainWindowOf(Model.Root.Manager);
- _hwndSrc = PresentationSource.FromDependencyObject(this) as HwndSource;
- _hwndSrcHook = FilterMessage;
- _hwndSrc.AddHook(_hwndSrcHook);
- // Restore maximize state
- var maximized = Model.Descendents().OfType().Any(l => l.IsMaximized);
- UpdateMaximizedState(maximized);
- }
-
- private void OnUnloaded(object sender, RoutedEventArgs e)
- {
- Unloaded -= OnUnloaded;
- if (_hwndSrc == null) return;
- _hwndSrc.RemoveHook(_hwndSrcHook);
- InternalClose();
- }
-
- private void OnClosing(object sender, CancelEventArgs e)
- {
- Closing -= OnClosing;
- // If this window was Closed not from InternalClose method,
- // mark it as closing to avoid "InvalidOperationException: : Cannot set Visibility to Visible or call Show, ShowDialog,
- // Close, or WindowInteropHelper.EnsureHandle while a Window is closing".
- if (!_isClosing) _isClosing = true;
- }
-
- private void OnSizeChanged(object sender, SizeChangedEventArgs e)
- {
- foreach (var posElement in Model.Descendents().OfType())
- {
- posElement.FloatingWidth = ActualWidth;
- posElement.FloatingHeight = ActualHeight;
- posElement.RaiseFloatingPropertiesUpdated();
- }
- }
-
- private void OnActivated(object sender, EventArgs e)
- {
- Activated -= OnActivated;
-
- if (!_attachDrag || Mouse.LeftButton != MouseButtonState.Pressed) return;
- var windowHandle = new WindowInteropHelper(this).Handle;
- var mousePosition = this.PointToScreenDPI(Mouse.GetPosition(this));
-
- // BugFix Issue #6
- // This code is initializes the drag when content (document or toolwindow) is dragged
- // A second chance back up plan if DragDelta is not set
- if (DragDelta == default) DragDelta = new Point(3, 3);
- Left = mousePosition.X - DragDelta.X; // BugFix Issue #6
- Top = mousePosition.Y - DragDelta.Y;
- _attachDrag = false;
- var lParam = new IntPtr(((int)mousePosition.X & 0xFFFF) | ((int)mousePosition.Y << 16));
- Win32Helper.SendMessage(windowHandle, Win32Helper.WM_NCLBUTTONDOWN, new IntPtr(Win32Helper.HT_CAPTION), lParam);
- }
-
- private void UpdatePositionAndSizeOfPanes()
- {
- foreach (var posElement in Model.Descendents().OfType())
- {
- posElement.FloatingLeft = Left;
- posElement.FloatingTop = Top;
- posElement.FloatingWidth = Width;
- posElement.FloatingHeight = Height;
- posElement.RaiseFloatingPropertiesUpdated();
- }
- }
-
- private void UpdateMaximizedState(bool isMaximized)
- {
- foreach (var posElement in Model.Descendents().OfType())
- posElement.IsMaximized = isMaximized;
- IsMaximized = isMaximized;
- _isInternalChange = true;
- WindowState = isMaximized ? WindowState.Maximized : WindowState.Normal;
- _isInternalChange = false;
- }
-
- private void UpdateDragPosition()
- {
- if (_dragService == null)
- {
- _dragService = new DragService(this);
- SetIsDragging(true);
- }
- var mousePosition = this.TransformToDeviceDPI(Win32Helper.GetMousePosition());
- _dragService.UpdateMouseLocation(mousePosition);
- }
-
- #endregion Private Methods
-
- public virtual void EnableBindings()
- {
- }
-
- public virtual void DisableBindings()
- {
- }
-
- #region Internal Classes
-
- protected internal class FloatingWindowContentHost : HwndHost
- {
- #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 };
- _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
- }
+ {
+ _internalCloseFlag = !closeInitiatedByUser;
+ if (_isClosing) return;
+ _isClosing = true;
+ Close();
+ }
+
+ #endregion Internal Methods
+
+ #region Overrides
+
+ ///
+ protected override void OnClosed(EventArgs e)
+ {
+ SizeChanged -= OnSizeChanged;
+ if (Content != null)
+ {
+ (Content as FloatingWindowContentHost)?.Dispose();
+ if (_hwndSrc != null)
+ {
+ _hwndSrc.RemoveHook(_hwndSrcHook);
+ _hwndSrc.Dispose();
+ _hwndSrc = null;
+ }
+ }
+ base.OnClosed(e);
+ }
+
+ ///
+ protected override void OnInitialized(EventArgs e)
+ {
+ CommandBindings.Add(new CommandBinding(Microsoft.Windows.Shell.SystemCommands.CloseWindowCommand,
+ (s, args) => Microsoft.Windows.Shell.SystemCommands.CloseWindow((Window)args.Parameter)));
+ CommandBindings.Add(new CommandBinding(Microsoft.Windows.Shell.SystemCommands.MaximizeWindowCommand,
+ (s, args) => Microsoft.Windows.Shell.SystemCommands.MaximizeWindow((Window)args.Parameter)));
+ CommandBindings.Add(new CommandBinding(Microsoft.Windows.Shell.SystemCommands.MinimizeWindowCommand,
+ (s, args) => Microsoft.Windows.Shell.SystemCommands.MinimizeWindow((Window)args.Parameter)));
+ CommandBindings.Add(new CommandBinding(Microsoft.Windows.Shell.SystemCommands.RestoreWindowCommand,
+ (s, args) => Microsoft.Windows.Shell.SystemCommands.RestoreWindow((Window)args.Parameter)));
+ //Debug.Assert(this.Owner != null);
+ base.OnInitialized(e);
+ }
+
+ #endregion Overrides
+
+ #region Private Methods
+
+ 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 };
+ }
+
+ private void OnLoaded(object sender, RoutedEventArgs e)
+ {
+ Loaded -= OnLoaded;
+ this.SetParentToMainWindowOf(Model.Root.Manager);
+ _hwndSrc = PresentationSource.FromDependencyObject(this) as HwndSource;
+ _hwndSrcHook = FilterMessage;
+ _hwndSrc.AddHook(_hwndSrcHook);
+ // Restore maximize state
+ var maximized = Model.Descendents().OfType().Any(l => l.IsMaximized);
+ UpdateMaximizedState(maximized);
+ }
+
+ private void OnUnloaded(object sender, RoutedEventArgs e)
+ {
+ Unloaded -= OnUnloaded;
+ if (_hwndSrc == null) return;
+ _hwndSrc.RemoveHook(_hwndSrcHook);
+ InternalClose();
+ }
+
+ private void OnClosing(object sender, CancelEventArgs e)
+ {
+ Closing -= OnClosing;
+ // If this window was Closed not from InternalClose method,
+ // mark it as closing to avoid "InvalidOperationException: : Cannot set Visibility to Visible or call Show, ShowDialog,
+ // Close, or WindowInteropHelper.EnsureHandle while a Window is closing".
+ if (!_isClosing) _isClosing = true;
+ }
+
+ private void OnSizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ foreach (var posElement in Model.Descendents().OfType())
+ {
+ posElement.FloatingWidth = ActualWidth;
+ posElement.FloatingHeight = ActualHeight;
+ posElement.RaiseFloatingPropertiesUpdated();
+ }
+ }
+
+ private void OnActivated(object sender, EventArgs e)
+ {
+ Activated -= OnActivated;
+
+ if (!_attachDrag || Mouse.LeftButton != MouseButtonState.Pressed) return;
+ var windowHandle = new WindowInteropHelper(this).Handle;
+ var mousePosition = this.PointToScreenDPI(Mouse.GetPosition(this));
+
+ // BugFix Issue #6
+ // This code is initializes the drag when content (document or toolwindow) is dragged
+ // A second chance back up plan if DragDelta is not set
+ if (DragDelta == default) DragDelta = new Point(3, 3);
+ Left = mousePosition.X - DragDelta.X; // BugFix Issue #6
+ Top = mousePosition.Y - DragDelta.Y;
+ _attachDrag = false;
+ var lParam = new IntPtr(((int)mousePosition.X & 0xFFFF) | ((int)mousePosition.Y << 16));
+ Win32Helper.SendMessage(windowHandle, Win32Helper.WM_NCLBUTTONDOWN, new IntPtr(Win32Helper.HT_CAPTION), lParam);
+ }
+
+ private void UpdatePositionAndSizeOfPanes()
+ {
+ foreach (var posElement in Model.Descendents().OfType())
+ {
+ posElement.FloatingLeft = Left;
+ posElement.FloatingTop = Top;
+ posElement.FloatingWidth = Width;
+ posElement.FloatingHeight = Height;
+ posElement.RaiseFloatingPropertiesUpdated();
+ }
+ }
+
+ private void UpdateMaximizedState(bool isMaximized)
+ {
+ foreach (var posElement in Model.Descendents().OfType())
+ posElement.IsMaximized = isMaximized;
+ IsMaximized = isMaximized;
+ _isInternalChange = true;
+ WindowState = isMaximized ? WindowState.Maximized : WindowState.Normal;
+ _isInternalChange = false;
+ }
+
+ private void UpdateDragPosition()
+ {
+ if (_dragService == null)
+ {
+ _dragService = new DragService(this);
+ SetIsDragging(true);
+ }
+ var mousePosition = this.TransformToDeviceDPI(Win32Helper.GetMousePosition());
+ _dragService.UpdateMouseLocation(mousePosition);
+ }
+
+ #endregion Private Methods
+
+ public virtual void EnableBindings()
+ {
+ }
+
+ public virtual void DisableBindings()
+ {
+ }
+
+ #region Internal Classes
+
+ protected internal class FloatingWindowContentHost : HwndHost
+ {
+ #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 };
+ _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/DockingManager.cs b/source/Components/AvalonDock/DockingManager.cs
index fe45fac0..ee78d7dd 100644
--- a/source/Components/AvalonDock/DockingManager.cs
+++ b/source/Components/AvalonDock/DockingManager.cs
@@ -1341,6 +1341,25 @@ public bool AllowMixedOrientation
#endregion IsVirtualizingLayoutDocument IsVirtualizingLayoutAnchorable
+
+ #region AutoWindowSizeWhenOpened
+
+ ///
+ /// Gets/sets the float window is auto size when dragged out
+ ///
+ [Bindable(true), Description("Gets/sets the floating window is auto size when floated out"), Category("FloatingWindow")]
+ public bool AutoWindowSizeWhenOpened
+ {
+ get { return (bool)GetValue(AutoWindowSizeWhenOpenedProperty); }
+ set { SetValue(AutoWindowSizeWhenOpenedProperty, value); }
+ }
+
+ public static readonly DependencyProperty AutoWindowSizeWhenOpenedProperty =
+ DependencyProperty.Register("AutoWindowSizeWhenOpened", typeof(bool), typeof(DockingManager), new PropertyMetadata(false));
+
+
+ #endregion AutoWindowSizeWhenOpened
+
#endregion Public Properties
#region Private Properties
diff --git a/source/TestApp/App.xaml b/source/TestApp/App.xaml
index b6cf5818..687deff4 100644
--- a/source/TestApp/App.xaml
+++ b/source/TestApp/App.xaml
@@ -25,7 +25,7 @@
Set this property to true to auto-size the demo LayoutAnchorable to the size of its containing control
when being dragged into floating mode
-->
-
+
diff --git a/source/TestApp/MainWindow.xaml b/source/TestApp/MainWindow.xaml
index 6a4da229..24fbd34a 100644
--- a/source/TestApp/MainWindow.xaml
+++ b/source/TestApp/MainWindow.xaml
@@ -64,6 +64,7 @@
x:Name="dockManager"
Grid.Row="1"
AllowMixedOrientation="True"
+ AutoWindowSizeWhenOpened="True"
DocumentClosing="DockManager_DocumentClosing"
IsVirtualizingAnchorable="True"
IsVirtualizingDocument="True">
From 8db4f445fa54bdd30c57b660e675e8a105ed60d2 Mon Sep 17 00:00:00 2001
From: Dirkster99
Date: Sun, 5 Jul 2020 09:17:28 +0200
Subject: [PATCH 2/5] Update README.md
---
README.md | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index 35018201..3fa3d966 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,11 @@
-| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.svg)](http://nuget.org/packages/Dirkster.AvalonDock) | Dirkster.AvalonDock |
-| ------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
-| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.Themes.Aero.svg)](http://nuget.org/packages/Dirkster.AvalonDock.Themes.Aero) | Dirkster.AvalonDock.Themes.Aero |
-| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.Themes.Expression.svg)](http://nuget.org/packages/Dirkster.AvalonDock.Themes.Expression) | Dirkster.AvalonDock.Themes.Expression |
-| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.Themes.Metro.svg)](http://nuget.org/packages/Dirkster.AvalonDock.Themes.Metro) | Dirkster.AvalonDock.Themes.Metro |
-| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.Themes.VS2010.svg)](http://nuget.org/packages/Dirkster.AvalonDock.Themes.VS2010) | Dirkster.AvalonDock.Themes.VS2010 |
-| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.Themes.VS2013.svg)](http://nuget.org/packages/Dirkster.AvalonDock.Themes.VS2013) | [Dirkster.AvalonDock.Themes.VS2013](https://github.com/Dirkster99/AvalonDock/wiki/WPF-VS-2013-Dark-Light-Demo-Client) |
+| Downloads | Packages | NuGet
+| :------------------------------------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------- | :--------------------------------------------------------------------------------
+| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.svg)](http://nuget.org/packages/Dirkster.AvalonDock) | Dirkster.AvalonDock | [Dirkster.AvalonDock](http://nuget.org/packages/Dirkster.AvalonDock)
+| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.Themes.Aero.svg)](http://nuget.org/packages/Dirkster.AvalonDock.Themes.Aero) | Dirkster.AvalonDock.Themes.Aero | [Dirkster.AvalonDock.Themes.Aero](http://nuget.org/packages/Dirkster.AvalonDock.Themes.Aero)
+| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.Themes.Expression.svg)](http://nuget.org/packages/Dirkster.AvalonDock.Themes.Expression) | Dirkster.AvalonDock.Themes.Expression | [Dirkster.AvalonDock.Themes.Expression](http://nuget.org/packages/Dirkster.AvalonDock.Themes.Expression)
+| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.Themes.Metro.svg)](http://nuget.org/packages/Dirkster.AvalonDock.Themes.Metro) | Dirkster.AvalonDock.Themes.Metro | [Dirkster.AvalonDock.Themes.Metro](http://nuget.org/packages/Dirkster.AvalonDock.Themes.Metro)
+| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.Themes.VS2010.svg)](http://nuget.org/packages/Dirkster.AvalonDock.Themes.VS2010) | Dirkster.AvalonDock.Themes.VS2010 | [Dirkster.AvalonDock.Themes.VS2010](http://nuget.org/packages/Dirkster.AvalonDock.Themes.VS2010)
+| [![NuGet](https://img.shields.io/nuget/dt/Dirkster.AvalonDock.Themes.VS2013.svg)](http://nuget.org/packages/Dirkster.AvalonDock.Themes.VS2013) | [Dirkster.AvalonDock.Themes.VS2013](https://github.com/Dirkster99/AvalonDock/wiki/WPF-VS-2013-Dark-Light-Demo-Client) | [Dirkster.AvalonDock.Themes.VS2013](http://nuget.org/packages/Dirkster.AvalonDock.Themes.VS2013)
![Net4](https://badgen.net/badge/Framework/.Net 4/blue) ![NetCore3](https://badgen.net/badge/Framework/NetCore 3/blue)
From 202b674ca3f8d7ea59d19781d17464d17aa6c36c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=88=98=E6=99=93=E9=9D=92?= <569132102@qq.com>
Date: Sun, 5 Jul 2020 15:23:20 +0800
Subject: [PATCH 3/5] Modify Demo
---
source/TestApp/MainWindow.xaml | 82 +++++++++++++++++-----------------
1 file changed, 41 insertions(+), 41 deletions(-)
diff --git a/source/TestApp/MainWindow.xaml b/source/TestApp/MainWindow.xaml
index 24fbd34a..a1168b86 100644
--- a/source/TestApp/MainWindow.xaml
+++ b/source/TestApp/MainWindow.xaml
@@ -60,7 +60,7 @@
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
@@ -102,19 +102,19 @@
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
@@ -122,33 +122,33 @@
-
-
+
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
From dbdbc9248eb0cbf6a640bdabe47b46d2b61fcdaa Mon Sep 17 00:00:00 2001
From: Dirkster99
Date: Sun, 5 Jul 2020 10:17:40 +0200
Subject: [PATCH 4/5] Code Cleanup
---
.../AvalonDock/Commands/IExecuteWithObject.cs | 58 +-
.../Commands/IExecuteWithObjectAndResult.cs | 30 +-
.../AvalonDock/Commands/NamespaceDoc.cs | 2 +-
.../AvalonDock/Commands/RelayCommand.cs | 380 ++++++-------
.../AvalonDock/Commands/WeakAction.cs | 518 +++++++++---------
.../AvalonDock/Commands/WeakActionGeneric.cs | 342 ++++++------
.../AvalonDock/Commands/WeakFunc.cs | 502 ++++++++---------
.../AvalonDock/Commands/WeakFuncGeneric.cs | 366 ++++++-------
8 files changed, 1099 insertions(+), 1099 deletions(-)
diff --git a/source/Components/AvalonDock/Commands/IExecuteWithObject.cs b/source/Components/AvalonDock/Commands/IExecuteWithObject.cs
index 3a081906..0dbea8f2 100644
--- a/source/Components/AvalonDock/Commands/IExecuteWithObject.cs
+++ b/source/Components/AvalonDock/Commands/IExecuteWithObject.cs
@@ -1,38 +1,38 @@
namespace AvalonDock.Commands
{
- ///
- /// Interface IExecuteWithObject
- ///
- internal interface IExecuteWithObject
- {
- #region Public Properties
+ ///
+ /// Interface IExecuteWithObject
+ ///
+ internal interface IExecuteWithObject
+ {
+ #region Public Properties
- ///
- /// The target of the WeakAction.
- ///
- /// The target.
- object Target
- {
- get;
- }
+ ///
+ /// The target of the WeakAction.
+ ///
+ /// The target.
+ object Target
+ {
+ get;
+ }
- #endregion Public Properties
+ #endregion Public Properties
- #region Public Methods
+ #region Public Methods
- ///
- /// Executes an action.
- ///
- /// A parameter passed as an object,
- /// to be casted to the appropriate type.
- void ExecuteWithObject(object parameter);
+ ///
+ /// Executes an action.
+ ///
+ /// A parameter passed as an object,
+ /// to be casted to the appropriate type.
+ void ExecuteWithObject(object parameter);
- ///
- /// Deletes all references, which notifies the cleanup method
- /// that this entry must be deleted.
- ///
- void MarkForDeletion();
+ ///
+ /// Deletes all references, which notifies the cleanup method
+ /// that this entry must be deleted.
+ ///
+ void MarkForDeletion();
- #endregion Public Methods
- }
+ #endregion Public Methods
+ }
}
\ No newline at end of file
diff --git a/source/Components/AvalonDock/Commands/IExecuteWithObjectAndResult.cs b/source/Components/AvalonDock/Commands/IExecuteWithObjectAndResult.cs
index 5590b270..f0117728 100644
--- a/source/Components/AvalonDock/Commands/IExecuteWithObjectAndResult.cs
+++ b/source/Components/AvalonDock/Commands/IExecuteWithObjectAndResult.cs
@@ -1,20 +1,20 @@
namespace AvalonDock.Commands
{
- ///
- /// Interface IExecuteWithObjectAndResult
- ///
- internal interface IExecuteWithObjectAndResult
- {
- #region Public Methods
+ ///
+ /// Interface IExecuteWithObjectAndResult
+ ///
+ internal interface IExecuteWithObjectAndResult
+ {
+ #region Public Methods
- ///
- /// Executes a Func and returns the result.
- ///
- /// A parameter passed as an object,
- /// to be casted to the appropriate type.
- /// The result of the operation.
- object ExecuteWithObject(object parameter);
+ ///
+ /// Executes a Func and returns the result.
+ ///
+ /// A parameter passed as an object,
+ /// to be casted to the appropriate type.
+ /// The result of the operation.
+ object ExecuteWithObject(object parameter);
- #endregion Public Methods
- }
+ #endregion Public Methods
+ }
}
\ No newline at end of file
diff --git a/source/Components/AvalonDock/Commands/NamespaceDoc.cs b/source/Components/AvalonDock/Commands/NamespaceDoc.cs
index 2f4b625e..39cd7c7f 100644
--- a/source/Components/AvalonDock/Commands/NamespaceDoc.cs
+++ b/source/Components/AvalonDock/Commands/NamespaceDoc.cs
@@ -5,4 +5,4 @@ namespace AvalonDock.Commands
internal class NamespaceDoc
{
}
-}
+}
\ No newline at end of file
diff --git a/source/Components/AvalonDock/Commands/RelayCommand.cs b/source/Components/AvalonDock/Commands/RelayCommand.cs
index 78a64e55..a0feb160 100644
--- a/source/Components/AvalonDock/Commands/RelayCommand.cs
+++ b/source/Components/AvalonDock/Commands/RelayCommand.cs
@@ -13,194 +13,194 @@ This program is provided to you under the terms of the Microsoft Public
namespace AvalonDock.Commands
{
- ///
- ///
- /// A command whose sole purpose is to relay its functionality to other
- /// objects by invoking delegates.
- /// The default return value for the method is true.
- ///
- /// Source:
- ///
- ///
- ///
- /// Class RelayCommand.
- ///
- ///
- ///
- internal class RelayCommand : ICommand
- {
- #region Private Fields
-
- ///
- /// The can execute
- ///
- private readonly WeakFunc _canExecute;
-
- ///
- /// The execute
- ///
- private readonly WeakAction _execute;
-
- #endregion Private Fields
-
- #region Public Constructors
-
- ///
- /// Initializes a new instance of the RelayCommand class that
- /// can always execute.
- ///
- /// The execution logic. IMPORTANT: Note that closures are not supported at the moment
- /// due to the use of WeakActions (see http://stackoverflow.com/questions/25730530/).
- /// If the execute argument is null.
- public RelayCommand(Action execute)
- : this(execute, null)
- {
- }
-
- ///
- /// Initializes a new instance of the RelayCommand class.
- ///
- /// The execution logic. IMPORTANT: Note that closures are not supported at the moment
- /// due to the use of WeakActions (see http://stackoverflow.com/questions/25730530/).
- /// The execution status logic. IMPORTANT: Note that closures are not supported at the moment
- /// due to the use of WeakActions (see http://stackoverflow.com/questions/25730530/).
- /// If the execute argument is null.
- public RelayCommand(Action execute, Func canExecute)
- {
- if (execute == null)
- {
- throw new ArgumentNullException("execute");
- }
-
- _execute = new WeakAction(execute);
-
- if (canExecute != null)
- {
- _canExecute = new WeakFunc(canExecute);
- }
- }
-
- #endregion Public Constructors
-
- #region Public Events
-
- ///
- /// Occurs when changes occur that affect whether the command should execute.
- ///
- public event EventHandler CanExecuteChanged
- {
- add
- {
- if (_canExecute != null)
- {
- CommandManager.RequerySuggested += value;
- }
- }
-
- remove
- {
- if (_canExecute != null)
- {
- CommandManager.RequerySuggested -= value;
- }
- }
- }
-
- #endregion Public Events
-
- #region Public Methods
-
- ///
- /// Defines the method that determines whether the command can execute in its current state.
- ///
- /// Data used by the command. If the command does not require data
- /// to be passed, this object can be set to a null reference
- /// true if this command can be executed; otherwise, false.
- public bool CanExecute(object parameter)
- {
- if (_canExecute == null)
- {
- return true;
- }
-
- if (_canExecute.IsStatic || _canExecute.IsAlive)
- {
- if (parameter == null && typeof(T).IsValueType)
- {
- return _canExecute.Execute(default);
- }
-
- if (parameter == null || parameter is T)
- {
- return (_canExecute.Execute((T)parameter));
- }
- }
-
- return false;
- }
-
- ///
- /// Defines the method to be called when the command is invoked.
- ///
- /// Data used by the command. If the command does not require data
- /// to be passed, this object can be set to a null reference
- public virtual void Execute(object parameter)
- {
- var val = parameter;
-
- if (parameter != null
- && parameter.GetType() != typeof(T))
- {
- if (typeof(T).IsEnum)
- {
- val = Enum.Parse(typeof(T), parameter.ToString());
- }
- else if (parameter is IConvertible)
- {
- val = Convert.ChangeType(parameter, typeof(T), null);
- }
- }
-
- if (CanExecute(val)
- && _execute != null
- && (_execute.IsStatic || _execute.IsAlive))
- {
- if (val == null)
- {
- if (typeof(T).IsValueType)
- {
- _execute.Execute(default);
- }
- else
- {
- // ReSharper disable ExpressionIsAlwaysNull
- _execute.Execute((T)val);
- // ReSharper restore ExpressionIsAlwaysNull
- }
- }
- else
- {
- _execute.Execute((T)val);
- }
- }
- }
-
- ///
- /// Raises the event.
- ///
- [SuppressMessage(
- "Microsoft.Performance",
- "CA1822:MarkMembersAsStatic",
- Justification = "The this keyword is used in the Silverlight version")]
- [SuppressMessage(
- "Microsoft.Design",
- "CA1030:UseEventsWhereAppropriate",
- Justification = "This cannot be an event")]
- public void RaiseCanExecuteChanged()
- {
- CommandManager.InvalidateRequerySuggested();
- }
-
- #endregion Public Methods
- }
+ ///
+ ///
+ /// A command whose sole purpose is to relay its functionality to other
+ /// objects by invoking delegates.
+ /// The default return value for the method is true.
+ ///
+ /// Source:
+ ///
+ ///
+ ///
+ /// Class RelayCommand.
+ ///
+ ///
+ ///
+ internal class RelayCommand : ICommand
+ {
+ #region Private Fields
+
+ ///
+ /// The can execute
+ ///
+ private readonly WeakFunc _canExecute;
+
+ ///
+ /// The execute
+ ///
+ private readonly WeakAction _execute;
+
+ #endregion Private Fields
+
+ #region Public Constructors
+
+ ///
+ /// Initializes a new instance of the RelayCommand class that
+ /// can always execute.
+ ///
+ /// The execution logic. IMPORTANT: Note that closures are not supported at the moment
+ /// due to the use of WeakActions (see http://stackoverflow.com/questions/25730530/).
+ /// If the execute argument is null.
+ public RelayCommand(Action execute)
+ : this(execute, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the RelayCommand class.
+ ///
+ /// The execution logic. IMPORTANT: Note that closures are not supported at the moment
+ /// due to the use of WeakActions (see http://stackoverflow.com/questions/25730530/).
+ /// The execution status logic. IMPORTANT: Note that closures are not supported at the moment
+ /// due to the use of WeakActions (see http://stackoverflow.com/questions/25730530/).
+ /// If the execute argument is null.
+ public RelayCommand(Action execute, Func canExecute)
+ {
+ if (execute == null)
+ {
+ throw new ArgumentNullException("execute");
+ }
+
+ _execute = new WeakAction(execute);
+
+ if (canExecute != null)
+ {
+ _canExecute = new WeakFunc(canExecute);
+ }
+ }
+
+ #endregion Public Constructors
+
+ #region Public Events
+
+ ///
+ /// Occurs when changes occur that affect whether the command should execute.
+ ///
+ public event EventHandler CanExecuteChanged
+ {
+ add
+ {
+ if (_canExecute != null)
+ {
+ CommandManager.RequerySuggested += value;
+ }
+ }
+
+ remove
+ {
+ if (_canExecute != null)
+ {
+ CommandManager.RequerySuggested -= value;
+ }
+ }
+ }
+
+ #endregion Public Events
+
+ #region Public Methods
+
+ ///
+ /// Defines the method that determines whether the command can execute in its current state.
+ ///
+ /// Data used by the command. If the command does not require data
+ /// to be passed, this object can be set to a null reference
+ /// true if this command can be executed; otherwise, false.
+ public bool CanExecute(object parameter)
+ {
+ if (_canExecute == null)
+ {
+ return true;
+ }
+
+ if (_canExecute.IsStatic || _canExecute.IsAlive)
+ {
+ if (parameter == null && typeof(T).IsValueType)
+ {
+ return _canExecute.Execute(default);
+ }
+
+ if (parameter == null || parameter is T)
+ {
+ return (_canExecute.Execute((T)parameter));
+ }
+ }
+
+ return false;
+ }
+
+ ///
+ /// Defines the method to be called when the command is invoked.
+ ///
+ /// Data used by the command. If the command does not require data
+ /// to be passed, this object can be set to a null reference
+ public virtual void Execute(object parameter)
+ {
+ var val = parameter;
+
+ if (parameter != null
+ && parameter.GetType() != typeof(T))
+ {
+ if (typeof(T).IsEnum)
+ {
+ val = Enum.Parse(typeof(T), parameter.ToString());
+ }
+ else if (parameter is IConvertible)
+ {
+ val = Convert.ChangeType(parameter, typeof(T), null);
+ }
+ }
+
+ if (CanExecute(val)
+ && _execute != null
+ && (_execute.IsStatic || _execute.IsAlive))
+ {
+ if (val == null)
+ {
+ if (typeof(T).IsValueType)
+ {
+ _execute.Execute(default);
+ }
+ else
+ {
+ // ReSharper disable ExpressionIsAlwaysNull
+ _execute.Execute((T)val);
+ // ReSharper restore ExpressionIsAlwaysNull
+ }
+ }
+ else
+ {
+ _execute.Execute((T)val);
+ }
+ }
+ }
+
+ ///
+ /// Raises the event.
+ ///
+ [SuppressMessage(
+ "Microsoft.Performance",
+ "CA1822:MarkMembersAsStatic",
+ Justification = "The this keyword is used in the Silverlight version")]
+ [SuppressMessage(
+ "Microsoft.Design",
+ "CA1030:UseEventsWhereAppropriate",
+ Justification = "This cannot be an event")]
+ public void RaiseCanExecuteChanged()
+ {
+ CommandManager.InvalidateRequerySuggested();
+ }
+
+ #endregion Public Methods
+ }
}
\ No newline at end of file
diff --git a/source/Components/AvalonDock/Commands/WeakAction.cs b/source/Components/AvalonDock/Commands/WeakAction.cs
index de8ccca7..932c08d4 100644
--- a/source/Components/AvalonDock/Commands/WeakAction.cs
+++ b/source/Components/AvalonDock/Commands/WeakAction.cs
@@ -5,255 +5,255 @@
namespace AvalonDock.Commands
{
- ///
- /// Class WeakAction.
- ///
- internal class WeakAction
- {
- #region Private Fields
-
- ///
- /// The static action
- ///
- private Action _staticAction;
-
- #endregion Private Fields
-
- #region Public Constructors
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The action that will be associated to this instance.
- public WeakAction(Action action)
- : this(action?.Target, action)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The action's owner.
- /// The action that will be associated to this instance.
- [SuppressMessage(
- "Microsoft.Design",
- "CA1062:Validate arguments of public methods",
- MessageId = "1",
- Justification = "Method should fail with an exception if action is null.")]
- public WeakAction(object target, Action action)
- {
- if (action.Method.IsStatic)
- {
- _staticAction = action;
-
- if (target != null)
- {
- // Keep a reference to the target to control the
- // WeakAction's lifetime.
- Reference = new WeakReference(target);
- }
-
- return;
- }
- Method = action.Method;
- ActionReference = new WeakReference(action.Target);
- Reference = new WeakReference(target);
- }
-
- #endregion Public Constructors
-
- #region Protected Constructors
-
- ///
- /// Initializes an empty instance of the class.
- ///
- protected WeakAction()
- {
- }
-
- #endregion Protected Constructors
-
- #region Public Properties
-
- ///
- /// Gets a value indicating whether the Action's owner is still alive, or if it was collected
- /// by the Garbage Collector already.
- ///
- /// true 如果 this instance is alive; 否则, false.
- public virtual bool IsAlive
- {
- get
- {
- if (_staticAction == null
- && Reference == null)
- {
- return false;
- }
-
- if (_staticAction != null)
- {
- if (Reference != null)
- {
- return Reference.IsAlive;
- }
-
- return true;
- }
-
- return Reference.IsAlive;
- }
- }
-
- ///
- /// Gets a value indicating whether the WeakAction is static or not.
- ///
- /// true 如果 this instance is static; 否则, false.
- public bool IsStatic
- {
- get
- {
+ ///
+ /// Class WeakAction.
+ ///
+ internal class WeakAction
+ {
+ #region Private Fields
+
+ ///
+ /// The static action
+ ///
+ private Action _staticAction;
+
+ #endregion Private Fields
+
+ #region Public Constructors
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The action that will be associated to this instance.
+ public WeakAction(Action action)
+ : this(action?.Target, action)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The action's owner.
+ /// The action that will be associated to this instance.
+ [SuppressMessage(
+ "Microsoft.Design",
+ "CA1062:Validate arguments of public methods",
+ MessageId = "1",
+ Justification = "Method should fail with an exception if action is null.")]
+ public WeakAction(object target, Action action)
+ {
+ if (action.Method.IsStatic)
+ {
+ _staticAction = action;
+
+ if (target != null)
+ {
+ // Keep a reference to the target to control the
+ // WeakAction's lifetime.
+ Reference = new WeakReference(target);
+ }
+
+ return;
+ }
+ Method = action.Method;
+ ActionReference = new WeakReference(action.Target);
+ Reference = new WeakReference(target);
+ }
+
+ #endregion Public Constructors
+
+ #region Protected Constructors
+
+ ///
+ /// Initializes an empty instance of the class.
+ ///
+ protected WeakAction()
+ {
+ }
+
+ #endregion Protected Constructors
+
+ #region Public Properties
+
+ ///
+ /// Gets a value indicating whether the Action's owner is still alive, or if it was collected
+ /// by the Garbage Collector already.
+ ///
+ /// true 如果 this instance is alive; 否则, false.
+ public virtual bool IsAlive
+ {
+ get
+ {
+ if (_staticAction == null
+ && Reference == null)
+ {
+ return false;
+ }
+
+ if (_staticAction != null)
+ {
+ if (Reference != null)
+ {
+ return Reference.IsAlive;
+ }
+
+ return true;
+ }
+
+ return Reference.IsAlive;
+ }
+ }
+
+ ///
+ /// Gets a value indicating whether the WeakAction is static or not.
+ ///
+ /// true 如果 this instance is static; 否则, false.
+ public bool IsStatic
+ {
+ get
+ {
#if SILVERLIGHT
return (_action != null && _action.Target == null)
|| _staticAction != null;
#else
- return _staticAction != null;
+ return _staticAction != null;
#endif
- }
- }
-
- ///
- /// Gets the name of the method that this WeakAction represents.
- ///
- /// The name of the method.
- public virtual string MethodName
- {
- get
- {
- if (_staticAction != null)
- {
- return _staticAction.Method.Name;
- }
- return Method.Name;
- }
- }
-
- ///
- /// Gets the Action's owner. This object is stored as a
- /// .
- ///
- /// The target.
- public object Target
- {
- get
- {
- if (Reference == null)
- {
- return null;
- }
-
- return Reference.Target;
- }
- }
-
- #endregion Public Properties
-
- #region Protected Properties
-
- ///
- /// Gets or sets a WeakReference to this WeakAction's action's target.
- /// This is not necessarily the same as
- /// , for example if the
- /// method is anonymous.
- ///
- /// The action reference.
- protected WeakReference ActionReference
- {
- get;
- set;
- }
-
- ///
- /// The target of the weak reference.
- ///
- /// The action target.
- protected object ActionTarget
- {
- get
- {
- if (ActionReference == null)
- {
- return null;
- }
-
- return ActionReference.Target;
- }
- }
-
- ///
- /// Gets or sets the corresponding to this WeakAction's
- /// method passed in the constructor.
- ///
- /// The method.
- protected MethodInfo Method
- {
- get;
- set;
- }
-
- ///
- /// Gets or sets a WeakReference to the target passed when constructing
- /// the WeakAction. This is not necessarily the same as
- /// , for example if the
- /// method is anonymous.
- ///
- /// The reference.
- protected WeakReference Reference
- {
- get;
- set;
- }
-
- #endregion Protected Properties
-
- #region Public Methods
-
- ///
- /// Executes the action. This only happens if the action's owner
- /// is still alive.
- ///
- public void Execute(object param = null)
- {
- if (_staticAction != null)
- {
- _staticAction();
- return;
- }
-
- var actionTarget = ActionTarget;
-
- if (IsAlive)
- {
- if (Method != null
- && ActionReference != null
- && actionTarget != null)
- {
- var paras = Method.GetParameters().Count();
- try
- {
- if (paras > 0)
- {
- Method.Invoke(actionTarget, new object[] { param });
- }
- else
- {
- Method.Invoke(actionTarget, null);
- }
- }
- catch { }
- // ReSharper disable RedundantJumpStatement
- return;
- // ReSharper restore RedundantJumpStatement
- }
+ }
+ }
+
+ ///
+ /// Gets the name of the method that this WeakAction represents.
+ ///
+ /// The name of the method.
+ public virtual string MethodName
+ {
+ get
+ {
+ if (_staticAction != null)
+ {
+ return _staticAction.Method.Name;
+ }
+ return Method.Name;
+ }
+ }
+
+ ///
+ /// Gets the Action's owner. This object is stored as a
+ /// .
+ ///
+ /// The target.
+ public object Target
+ {
+ get
+ {
+ if (Reference == null)
+ {
+ return null;
+ }
+
+ return Reference.Target;
+ }
+ }
+
+ #endregion Public Properties
+
+ #region Protected Properties
+
+ ///
+ /// Gets or sets a WeakReference to this WeakAction's action's target.
+ /// This is not necessarily the same as
+ /// , for example if the
+ /// method is anonymous.
+ ///
+ /// The action reference.
+ protected WeakReference ActionReference
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// The target of the weak reference.
+ ///
+ /// The action target.
+ protected object ActionTarget
+ {
+ get
+ {
+ if (ActionReference == null)
+ {
+ return null;
+ }
+
+ return ActionReference.Target;
+ }
+ }
+
+ ///
+ /// Gets or sets the corresponding to this WeakAction's
+ /// method passed in the constructor.
+ ///
+ /// The method.
+ protected MethodInfo Method
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// Gets or sets a WeakReference to the target passed when constructing
+ /// the WeakAction. This is not necessarily the same as
+ /// , for example if the
+ /// method is anonymous.
+ ///
+ /// The reference.
+ protected WeakReference Reference
+ {
+ get;
+ set;
+ }
+
+ #endregion Protected Properties
+
+ #region Public Methods
+
+ ///
+ /// Executes the action. This only happens if the action's owner
+ /// is still alive.
+ ///
+ public void Execute(object param = null)
+ {
+ if (_staticAction != null)
+ {
+ _staticAction();
+ return;
+ }
+
+ var actionTarget = ActionTarget;
+
+ if (IsAlive)
+ {
+ if (Method != null
+ && ActionReference != null
+ && actionTarget != null)
+ {
+ var paras = Method.GetParameters().Count();
+ try
+ {
+ if (paras > 0)
+ {
+ Method.Invoke(actionTarget, new object[] { param });
+ }
+ else
+ {
+ Method.Invoke(actionTarget, null);
+ }
+ }
+ catch { }
+ // ReSharper disable RedundantJumpStatement
+ return;
+ // ReSharper restore RedundantJumpStatement
+ }
#if SILVERLIGHT
if (_action != null)
@@ -261,24 +261,24 @@ public void Execute(object param = null)
_action();
}
#endif
- }
- }
-
- ///
- /// Sets the reference that this instance stores to null.
- ///
- public void MarkForDeletion()
- {
- Reference = null;
- ActionReference = null;
- Method = null;
- _staticAction = null;
+ }
+ }
+
+ ///
+ /// Sets the reference that this instance stores to null.
+ ///
+ public void MarkForDeletion()
+ {
+ Reference = null;
+ ActionReference = null;
+ Method = null;
+ _staticAction = null;
#if SILVERLIGHT
_action = null;
#endif
- }
+ }
- #endregion Public Methods
- }
+ #endregion Public Methods
+ }
}
\ No newline at end of file
diff --git a/source/Components/AvalonDock/Commands/WeakActionGeneric.cs b/source/Components/AvalonDock/Commands/WeakActionGeneric.cs
index f80574d8..db84ec46 100644
--- a/source/Components/AvalonDock/Commands/WeakActionGeneric.cs
+++ b/source/Components/AvalonDock/Commands/WeakActionGeneric.cs
@@ -3,175 +3,175 @@
namespace AvalonDock.Commands
{
- internal class WeakAction : WeakAction, IExecuteWithObject
- {
- #region Private Fields
-
- private Action _staticAction;
-
- #endregion Private Fields
-
- #region Public Constructors
-
- ///
- /// Initializes a new instance of the WeakAction class.
- ///
- /// The action that will be associated to this instance.
- public WeakAction(Action action)
- : this(action?.Target, action)
- {
- }
-
- ///
- /// Initializes a new instance of the WeakAction class.
- ///
- /// The action's owner.
- /// The action that will be associated to this instance.
- [SuppressMessage(
- "Microsoft.Design",
- "CA1062:Validate arguments of public methods",
- MessageId = "1",
- Justification = "Method should fail with an exception if action is null.")]
- public WeakAction(object target, Action action)
- {
- if (action.Method.IsStatic)
- {
- _staticAction = action;
-
- if (target != null)
- {
- // Keep a reference to the target to control the
- // WeakAction's lifetime.
- Reference = new WeakReference(target);
- }
-
- return;
- }
- Method = action.Method;
- ActionReference = new WeakReference(action.Target);
- Reference = new WeakReference(target);
- }
-
- #endregion Public Constructors
-
- #region Public Properties
-
- ///
- /// Gets a value indicating whether the Action's owner is still alive, or if it was collected
- /// by the Garbage Collector already.
- ///
- public override bool IsAlive
- {
- get
- {
- if (_staticAction == null
- && Reference == null)
- {
- return false;
- }
-
- if (_staticAction != null)
- {
- if (Reference != null)
- {
- return Reference.IsAlive;
- }
-
- return true;
- }
-
- return Reference.IsAlive;
- }
- }
-
- ///
- /// Gets the name of the method that this WeakAction represents.
- ///
- public override string MethodName
- {
- get
- {
- if (_staticAction != null)
- {
- return _staticAction.Method.Name;
- }
- return Method.Name;
- }
- }
-
- #endregion Public Properties
-
- #region Public Methods
-
- ///
- /// Executes the action. This only happens if the action's owner
- /// is still alive. The action's parameter is set to default(T).
- ///
- public void Execute()
- {
- Execute(default);
- }
-
- ///
- /// Executes the action. This only happens if the action's owner
- /// is still alive.
- ///
- /// A parameter to be passed to the action.
- public void Execute(T parameter)
- {
- if (_staticAction != null)
- {
- _staticAction(parameter);
- return;
- }
-
- var actionTarget = ActionTarget;
-
- if (IsAlive)
- {
- if (Method != null
- && ActionReference != null
- && actionTarget != null)
- {
- try
- {
- Method.Invoke(
- actionTarget,
- new object[]
- {
- parameter
- });
- }
- catch { }
- }
- }
- }
-
- ///
- /// Executes the action with a parameter of type object. This parameter
- /// will be casted to T. This method implements
- /// and can be useful if you store multiple WeakAction{T} instances but don't know in advance
- /// what type T represents.
- ///
- /// The parameter that will be passed to the action after
- /// being casted to T.
- public void ExecuteWithObject(object parameter)
- {
- var parameterCasted = (T)parameter;
- Execute(parameterCasted);
- }
-
- ///
- /// Sets all the actions that this WeakAction contains to null,
- /// which is a signal for containing objects that this WeakAction
- /// should be deleted.
- ///
- public new void MarkForDeletion()
- {
- _staticAction = null;
- base.MarkForDeletion();
- }
-
- #endregion Public Methods
- }
+ internal class WeakAction : WeakAction, IExecuteWithObject
+ {
+ #region Private Fields
+
+ private Action _staticAction;
+
+ #endregion Private Fields
+
+ #region Public Constructors
+
+ ///
+ /// Initializes a new instance of the WeakAction class.
+ ///
+ /// The action that will be associated to this instance.
+ public WeakAction(Action action)
+ : this(action?.Target, action)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the WeakAction class.
+ ///
+ /// The action's owner.
+ /// The action that will be associated to this instance.
+ [SuppressMessage(
+ "Microsoft.Design",
+ "CA1062:Validate arguments of public methods",
+ MessageId = "1",
+ Justification = "Method should fail with an exception if action is null.")]
+ public WeakAction(object target, Action action)
+ {
+ if (action.Method.IsStatic)
+ {
+ _staticAction = action;
+
+ if (target != null)
+ {
+ // Keep a reference to the target to control the
+ // WeakAction's lifetime.
+ Reference = new WeakReference(target);
+ }
+
+ return;
+ }
+ Method = action.Method;
+ ActionReference = new WeakReference(action.Target);
+ Reference = new WeakReference(target);
+ }
+
+ #endregion Public Constructors
+
+ #region Public Properties
+
+ ///
+ /// Gets a value indicating whether the Action's owner is still alive, or if it was collected
+ /// by the Garbage Collector already.
+ ///
+ public override bool IsAlive
+ {
+ get
+ {
+ if (_staticAction == null
+ && Reference == null)
+ {
+ return false;
+ }
+
+ if (_staticAction != null)
+ {
+ if (Reference != null)
+ {
+ return Reference.IsAlive;
+ }
+
+ return true;
+ }
+
+ return Reference.IsAlive;
+ }
+ }
+
+ ///
+ /// Gets the name of the method that this WeakAction represents.
+ ///
+ public override string MethodName
+ {
+ get
+ {
+ if (_staticAction != null)
+ {
+ return _staticAction.Method.Name;
+ }
+ return Method.Name;
+ }
+ }
+
+ #endregion Public Properties
+
+ #region Public Methods
+
+ ///
+ /// Executes the action. This only happens if the action's owner
+ /// is still alive. The action's parameter is set to default(T).
+ ///
+ public void Execute()
+ {
+ Execute(default);
+ }
+
+ ///
+ /// Executes the action. This only happens if the action's owner
+ /// is still alive.
+ ///
+ /// A parameter to be passed to the action.
+ public void Execute(T parameter)
+ {
+ if (_staticAction != null)
+ {
+ _staticAction(parameter);
+ return;
+ }
+
+ var actionTarget = ActionTarget;
+
+ if (IsAlive)
+ {
+ if (Method != null
+ && ActionReference != null
+ && actionTarget != null)
+ {
+ try
+ {
+ Method.Invoke(
+ actionTarget,
+ new object[]
+ {
+ parameter
+ });
+ }
+ catch { }
+ }
+ }
+ }
+
+ ///
+ /// Executes the action with a parameter of type object. This parameter
+ /// will be casted to T. This method implements
+ /// and can be useful if you store multiple WeakAction{T} instances but don't know in advance
+ /// what type T represents.
+ ///
+ /// The parameter that will be passed to the action after
+ /// being casted to T.
+ public void ExecuteWithObject(object parameter)
+ {
+ var parameterCasted = (T)parameter;
+ Execute(parameterCasted);
+ }
+
+ ///
+ /// Sets all the actions that this WeakAction contains to null,
+ /// which is a signal for containing objects that this WeakAction
+ /// should be deleted.
+ ///
+ public new void MarkForDeletion()
+ {
+ _staticAction = null;
+ base.MarkForDeletion();
+ }
+
+ #endregion Public Methods
+ }
}
\ No newline at end of file
diff --git a/source/Components/AvalonDock/Commands/WeakFunc.cs b/source/Components/AvalonDock/Commands/WeakFunc.cs
index 188b09ef..49e18708 100644
--- a/source/Components/AvalonDock/Commands/WeakFunc.cs
+++ b/source/Components/AvalonDock/Commands/WeakFunc.cs
@@ -4,255 +4,255 @@
namespace AvalonDock.Commands
{
- ///
- /// Class WeakFunc.
- ///
- /// The type of the t result.
- internal class WeakFunc
- {
- #region Private Fields
-
- ///
- /// The static function
- ///
- private Func _staticFunc;
-
- #endregion Private Fields
-
- #region Public Constructors
-
- ///
- /// Initializes a new instance of the WeakFunc class.
- ///
- /// The Func that will be associated to this instance.
- public WeakFunc(Func func)
- : this(func?.Target, func)
- {
- }
-
- ///
- /// Initializes a new instance of the WeakFunc class.
- ///
- /// The Func's owner.
- /// The Func that will be associated to this instance.
- [SuppressMessage(
- "Microsoft.Design",
- "CA1062:Validate arguments of public methods",
- MessageId = "1",
- Justification = "Method should fail with an exception if func is null.")]
- public WeakFunc(object target, Func func)
- {
- if (func.Method.IsStatic)
- {
- _staticFunc = func;
-
- if (target != null)
- {
- // Keep a reference to the target to control the
- // WeakAction's lifetime.
- Reference = new WeakReference(target);
- }
-
- return;
- }
- Method = func.Method;
- FuncReference = new WeakReference(func.Target);
- Reference = new WeakReference(target);
- }
-
- #endregion Public Constructors
-
- #region Protected Constructors
-
- ///
- /// Initializes an empty instance of the WeakFunc class.
- ///
- protected WeakFunc()
- {
- }
-
- #endregion Protected Constructors
-
- #region Public Properties
-
- ///
- /// Gets a value indicating whether the Func's owner is still alive, or if it was collected
- /// by the Garbage Collector already.
- ///
- /// true 如果 this instance is alive; 否则, false.
- public virtual bool IsAlive
- {
- get
- {
- if (_staticFunc == null
- && Reference == null)
- {
- return false;
- }
-
- if (_staticFunc != null)
- {
- if (Reference != null)
- {
- return Reference.IsAlive;
- }
-
- return true;
- }
-
- return Reference.IsAlive;
- }
- }
-
- ///
- /// Get a value indicating whether the WeakFunc is static or not.
- ///
- /// true 如果 this instance is static; 否则, false.
- public bool IsStatic
- {
- get
- {
- return _staticFunc != null;
- }
- }
-
- ///
- /// Gets the name of the method that this WeakFunc represents.
- ///
- /// The name of the method.
- public virtual string MethodName
- {
- get
- {
- if (_staticFunc != null)
- {
- return _staticFunc.Method.Name;
- }
- return Method.Name;
- }
- }
-
- ///
- /// Gets the Func's owner. This object is stored as a
- /// .
- ///
- /// The target.
- public object Target
- {
- get
- {
- if (Reference == null)
- {
- return null;
- }
-
- return Reference.Target;
- }
- }
-
- #endregion Public Properties
-
- #region Protected Properties
-
- ///
- /// Gets or sets a WeakReference to this WeakFunc's action's target.
- /// This is not necessarily the same as
- /// , for example if the
- /// method is anonymous.
- ///
- /// The function reference.
- protected WeakReference FuncReference
- {
- get;
- set;
- }
-
- ///
- /// Gets the owner of the Func that was passed as parameter.
- /// This is not necessarily the same as
- /// , for example if the
- /// method is anonymous.
- ///
- /// The function target.
- protected object FuncTarget
- {
- get
- {
- if (FuncReference == null)
- {
- return null;
- }
-
- return FuncReference.Target;
- }
- }
-
- ///
- /// Gets or sets the corresponding to this WeakFunc's
- /// method passed in the constructor.
- ///
- /// The method.
- protected MethodInfo Method
- {
- get;
- set;
- }
-
- ///
- /// Gets or sets a WeakReference to the target passed when constructing
- /// the WeakFunc. This is not necessarily the same as
- /// , for example if the
- /// method is anonymous.
- ///
- /// The reference.
- protected WeakReference Reference
- {
- get;
- set;
- }
-
- #endregion Protected Properties
-
- #region Public Methods
-
- ///
- /// Executes the action. This only happens if the Func's owner
- /// is still alive.
- ///
- /// The result of the Func stored as reference.
- public TResult Execute()
- {
- if (_staticFunc != null)
- {
- return _staticFunc();
- }
-
- var funcTarget = FuncTarget;
-
- if (IsAlive)
- {
- if (Method != null
- && FuncReference != null
- && funcTarget != null)
- {
- return (TResult)Method.Invoke(funcTarget, null);
- }
- }
-
- return default;
- }
-
- ///
- /// Sets the reference that this instance stores to null.
- ///
- public void MarkForDeletion()
- {
- Reference = null;
- FuncReference = null;
- Method = null;
- _staticFunc = null;
- }
-
- #endregion Public Methods
- }
+ ///
+ /// Class WeakFunc.
+ ///
+ /// The type of the t result.
+ internal class WeakFunc
+ {
+ #region Private Fields
+
+ ///
+ /// The static function
+ ///
+ private Func _staticFunc;
+
+ #endregion Private Fields
+
+ #region Public Constructors
+
+ ///
+ /// Initializes a new instance of the WeakFunc class.
+ ///
+ /// The Func that will be associated to this instance.
+ public WeakFunc(Func func)
+ : this(func?.Target, func)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the WeakFunc class.
+ ///
+ /// The Func's owner.
+ /// The Func that will be associated to this instance.
+ [SuppressMessage(
+ "Microsoft.Design",
+ "CA1062:Validate arguments of public methods",
+ MessageId = "1",
+ Justification = "Method should fail with an exception if func is null.")]
+ public WeakFunc(object target, Func func)
+ {
+ if (func.Method.IsStatic)
+ {
+ _staticFunc = func;
+
+ if (target != null)
+ {
+ // Keep a reference to the target to control the
+ // WeakAction's lifetime.
+ Reference = new WeakReference(target);
+ }
+
+ return;
+ }
+ Method = func.Method;
+ FuncReference = new WeakReference(func.Target);
+ Reference = new WeakReference(target);
+ }
+
+ #endregion Public Constructors
+
+ #region Protected Constructors
+
+ ///
+ /// Initializes an empty instance of the WeakFunc class.
+ ///
+ protected WeakFunc()
+ {
+ }
+
+ #endregion Protected Constructors
+
+ #region Public Properties
+
+ ///
+ /// Gets a value indicating whether the Func's owner is still alive, or if it was collected
+ /// by the Garbage Collector already.
+ ///
+ /// true 如果 this instance is alive; 否则, false.
+ public virtual bool IsAlive
+ {
+ get
+ {
+ if (_staticFunc == null
+ && Reference == null)
+ {
+ return false;
+ }
+
+ if (_staticFunc != null)
+ {
+ if (Reference != null)
+ {
+ return Reference.IsAlive;
+ }
+
+ return true;
+ }
+
+ return Reference.IsAlive;
+ }
+ }
+
+ ///
+ /// Get a value indicating whether the WeakFunc is static or not.
+ ///
+ /// true 如果 this instance is static; 否则, false.
+ public bool IsStatic
+ {
+ get
+ {
+ return _staticFunc != null;
+ }
+ }
+
+ ///
+ /// Gets the name of the method that this WeakFunc represents.
+ ///
+ /// The name of the method.
+ public virtual string MethodName
+ {
+ get
+ {
+ if (_staticFunc != null)
+ {
+ return _staticFunc.Method.Name;
+ }
+ return Method.Name;
+ }
+ }
+
+ ///
+ /// Gets the Func's owner. This object is stored as a
+ /// .
+ ///
+ /// The target.
+ public object Target
+ {
+ get
+ {
+ if (Reference == null)
+ {
+ return null;
+ }
+
+ return Reference.Target;
+ }
+ }
+
+ #endregion Public Properties
+
+ #region Protected Properties
+
+ ///
+ /// Gets or sets a WeakReference to this WeakFunc's action's target.
+ /// This is not necessarily the same as
+ /// , for example if the
+ /// method is anonymous.
+ ///
+ /// The function reference.
+ protected WeakReference FuncReference
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// Gets the owner of the Func that was passed as parameter.
+ /// This is not necessarily the same as
+ /// , for example if the
+ /// method is anonymous.
+ ///
+ /// The function target.
+ protected object FuncTarget
+ {
+ get
+ {
+ if (FuncReference == null)
+ {
+ return null;
+ }
+
+ return FuncReference.Target;
+ }
+ }
+
+ ///
+ /// Gets or sets the corresponding to this WeakFunc's
+ /// method passed in the constructor.
+ ///
+ /// The method.
+ protected MethodInfo Method
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// Gets or sets a WeakReference to the target passed when constructing
+ /// the WeakFunc. This is not necessarily the same as
+ /// , for example if the
+ /// method is anonymous.
+ ///
+ /// The reference.
+ protected WeakReference Reference
+ {
+ get;
+ set;
+ }
+
+ #endregion Protected Properties
+
+ #region Public Methods
+
+ ///
+ /// Executes the action. This only happens if the Func's owner
+ /// is still alive.
+ ///
+ /// The result of the Func stored as reference.
+ public TResult Execute()
+ {
+ if (_staticFunc != null)
+ {
+ return _staticFunc();
+ }
+
+ var funcTarget = FuncTarget;
+
+ if (IsAlive)
+ {
+ if (Method != null
+ && FuncReference != null
+ && funcTarget != null)
+ {
+ return (TResult)Method.Invoke(funcTarget, null);
+ }
+ }
+
+ return default;
+ }
+
+ ///
+ /// Sets the reference that this instance stores to null.
+ ///
+ public void MarkForDeletion()
+ {
+ Reference = null;
+ FuncReference = null;
+ Method = null;
+ _staticFunc = null;
+ }
+
+ #endregion Public Methods
+ }
}
\ No newline at end of file
diff --git a/source/Components/AvalonDock/Commands/WeakFuncGeneric.cs b/source/Components/AvalonDock/Commands/WeakFuncGeneric.cs
index 0bc9e055..1e42f573 100644
--- a/source/Components/AvalonDock/Commands/WeakFuncGeneric.cs
+++ b/source/Components/AvalonDock/Commands/WeakFuncGeneric.cs
@@ -3,187 +3,187 @@
namespace AvalonDock.Commands
{
- ///
- /// Class WeakFunc.
- ///
- ///
- /// The type of the t result.
- ///
- ///
- internal class WeakFunc : WeakFunc, IExecuteWithObjectAndResult
- {
- #region Private Fields
-
- ///
- /// The static function
- ///
- private Func _staticFunc;
-
- #endregion Private Fields
-
- #region Public Constructors
-
- ///
- /// Initializes a new instance of the WeakFunc class.
- ///
- /// The Func that will be associated to this instance.
- public WeakFunc(Func func)
- : this(func?.Target, func)
- {
- }
-
- ///
- /// Initializes a new instance of the WeakFunc class.
- ///
- /// The Func's owner.
- /// The Func that will be associated to this instance.
- [SuppressMessage(
- "Microsoft.Design",
- "CA1062:Validate arguments of public methods",
- MessageId = "1",
- Justification = "Method should fail with an exception if func is null.")]
- public WeakFunc(object target, Func func)
- {
- if (func.Method.IsStatic)
- {
- _staticFunc = func;
-
- if (target != null)
- {
- // Keep a reference to the target to control the
- // WeakAction's lifetime.
- Reference = new WeakReference(target);
- }
-
- return;
- }
- Method = func.Method;
- FuncReference = new WeakReference(func.Target);
- Reference = new WeakReference(target);
- }
-
- #endregion Public Constructors
-
- #region Public Properties
-
- ///
- /// Gets a value indicating whether the Func's owner is still alive, or if it was collected
- /// by the Garbage Collector already.
- ///
- /// true 如果 this instance is alive; 否则, false.
- public override bool IsAlive
- {
- get
- {
- if (_staticFunc == null
- && Reference == null)
- {
- return false;
- }
-
- if (_staticFunc != null)
- {
- if (Reference != null)
- {
- return Reference.IsAlive;
- }
-
- return true;
- }
-
- return Reference.IsAlive;
- }
- }
-
- ///
- /// Gets or sets the name of the method that this WeakFunc represents.
- ///
- /// The name of the method.
- public override string MethodName
- {
- get
- {
- if (_staticFunc != null)
- {
- return _staticFunc.Method.Name;
- }
- return Method.Name;
- }
- }
-
- #endregion Public Properties
-
- #region Public Methods
-
- ///
- /// Executes the Func. This only happens if the Func's owner
- /// is still alive. The Func's parameter is set to default(T).
- ///
- /// The result of the Func stored as reference.
- public new TResult Execute()
- {
- return Execute(default);
- }
-
- ///
- /// Executes the Func. This only happens if the Func's owner
- /// is still alive.
- ///
- /// A parameter to be passed to the action.
- /// The result of the Func stored as reference.
- public TResult Execute(T parameter)
- {
- if (_staticFunc != null)
- {
- return _staticFunc(parameter);
- }
-
- var funcTarget = FuncTarget;
-
- if (IsAlive)
- {
- if (Method != null
- && FuncReference != null
- && funcTarget != null)
- {
- return (TResult)Method.Invoke(
- funcTarget,
- new object[]
- {
- parameter
- });
- }
- }
-
- return default;
- }
-
- ///
- /// Executes the Func with a parameter of type object. This parameter
- /// will be casted to T. This method implements
- /// and can be useful if you store multiple WeakFunc{T} instances but don't know in advance
- /// what type T represents.
- ///
- /// The parameter that will be passed to the Func after
- /// being casted to T.
- /// The result of the execution as object, to be casted to T.
- public object ExecuteWithObject(object parameter)
- {
- var parameterCasted = (T)parameter;
- return Execute(parameterCasted);
- }
-
- ///
- /// Sets all the funcs that this WeakFunc contains to null,
- /// which is a signal for containing objects that this WeakFunc
- /// should be deleted.
- ///
- public new void MarkForDeletion()
- {
- _staticFunc = null;
- base.MarkForDeletion();
- }
-
- #endregion Public Methods
- }
+ ///
+ /// Class WeakFunc.
+ ///
+ ///
+ /// The type of the t result.
+ ///
+ ///
+ internal class WeakFunc : WeakFunc, IExecuteWithObjectAndResult
+ {
+ #region Private Fields
+
+ ///
+ /// The static function
+ ///
+ private Func _staticFunc;
+
+ #endregion Private Fields
+
+ #region Public Constructors
+
+ ///
+ /// Initializes a new instance of the WeakFunc class.
+ ///
+ /// The Func that will be associated to this instance.
+ public WeakFunc(Func func)
+ : this(func?.Target, func)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the WeakFunc class.
+ ///
+ /// The Func's owner.
+ /// The Func that will be associated to this instance.
+ [SuppressMessage(
+ "Microsoft.Design",
+ "CA1062:Validate arguments of public methods",
+ MessageId = "1",
+ Justification = "Method should fail with an exception if func is null.")]
+ public WeakFunc(object target, Func func)
+ {
+ if (func.Method.IsStatic)
+ {
+ _staticFunc = func;
+
+ if (target != null)
+ {
+ // Keep a reference to the target to control the
+ // WeakAction's lifetime.
+ Reference = new WeakReference(target);
+ }
+
+ return;
+ }
+ Method = func.Method;
+ FuncReference = new WeakReference(func.Target);
+ Reference = new WeakReference(target);
+ }
+
+ #endregion Public Constructors
+
+ #region Public Properties
+
+ ///
+ /// Gets a value indicating whether the Func's owner is still alive, or if it was collected
+ /// by the Garbage Collector already.
+ ///
+ /// true 如果 this instance is alive; 否则, false.
+ public override bool IsAlive
+ {
+ get
+ {
+ if (_staticFunc == null
+ && Reference == null)
+ {
+ return false;
+ }
+
+ if (_staticFunc != null)
+ {
+ if (Reference != null)
+ {
+ return Reference.IsAlive;
+ }
+
+ return true;
+ }
+
+ return Reference.IsAlive;
+ }
+ }
+
+ ///
+ /// Gets or sets the name of the method that this WeakFunc represents.
+ ///
+ /// The name of the method.
+ public override string MethodName
+ {
+ get
+ {
+ if (_staticFunc != null)
+ {
+ return _staticFunc.Method.Name;
+ }
+ return Method.Name;
+ }
+ }
+
+ #endregion Public Properties
+
+ #region Public Methods
+
+ ///
+ /// Executes the Func. This only happens if the Func's owner
+ /// is still alive. The Func's parameter is set to default(T).
+ ///
+ /// The result of the Func stored as reference.
+ public new TResult Execute()
+ {
+ return Execute(default);
+ }
+
+ ///
+ /// Executes the Func. This only happens if the Func's owner
+ /// is still alive.
+ ///
+ /// A parameter to be passed to the action.
+ /// The result of the Func stored as reference.
+ public TResult Execute(T parameter)
+ {
+ if (_staticFunc != null)
+ {
+ return _staticFunc(parameter);
+ }
+
+ var funcTarget = FuncTarget;
+
+ if (IsAlive)
+ {
+ if (Method != null
+ && FuncReference != null
+ && funcTarget != null)
+ {
+ return (TResult)Method.Invoke(
+ funcTarget,
+ new object[]
+ {
+ parameter
+ });
+ }
+ }
+
+ return default;
+ }
+
+ ///
+ /// Executes the Func with a parameter of type object. This parameter
+ /// will be casted to T. This method implements
+ /// and can be useful if you store multiple WeakFunc{T} instances but don't know in advance
+ /// what type T represents.
+ ///
+ /// The parameter that will be passed to the Func after
+ /// being casted to T.
+ /// The result of the execution as object, to be casted to T.
+ public object ExecuteWithObject(object parameter)
+ {
+ var parameterCasted = (T)parameter;
+ return Execute(parameterCasted);
+ }
+
+ ///
+ /// Sets all the funcs that this WeakFunc contains to null,
+ /// which is a signal for containing objects that this WeakFunc
+ /// should be deleted.
+ ///
+ public new void MarkForDeletion()
+ {
+ _staticFunc = null;
+ base.MarkForDeletion();
+ }
+
+ #endregion Public Methods
+ }
}
\ No newline at end of file
From e18c09861e9acc6f2b2d76d34c6866e229b8b8c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=88=98=E6=99=93=E9=9D=92?= <569132102@qq.com>
Date: Mon, 6 Jul 2020 10:56:02 +0800
Subject: [PATCH 5/5] Fix #177
---
source/Components/AvalonDock.Themes.VS2013/Themes/Generic.xaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source/Components/AvalonDock.Themes.VS2013/Themes/Generic.xaml b/source/Components/AvalonDock.Themes.VS2013/Themes/Generic.xaml
index 8d2ea0af..56c17484 100644
--- a/source/Components/AvalonDock.Themes.VS2013/Themes/Generic.xaml
+++ b/source/Components/AvalonDock.Themes.VS2013/Themes/Generic.xaml
@@ -269,7 +269,7 @@
-
+