| 
														
															@@ -10,12 +10,13 @@ namespace Avalonia.Layout 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     /// <summary> 
														 | 
														
														 | 
														
															     /// <summary> 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     /// Manages measuring and arranging of controls. 
														 | 
														
														 | 
														
															     /// Manages measuring and arranging of controls. 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     /// </summary> 
														 | 
														
														 | 
														
															     /// </summary> 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-    public class LayoutManager : ILayoutManager 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+    public class LayoutManager : ILayoutManager, IDisposable 
														 | 
													
												
											
												
													
														| 
														 | 
														
															     { 
														 | 
														
														 | 
														
															     { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         private readonly ILayoutRoot _owner; 
														 | 
														
														 | 
														
															         private readonly ILayoutRoot _owner; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         private readonly LayoutQueue<ILayoutable> _toMeasure = new LayoutQueue<ILayoutable>(v => !v.IsMeasureValid); 
														 | 
														
														 | 
														
															         private readonly LayoutQueue<ILayoutable> _toMeasure = new LayoutQueue<ILayoutable>(v => !v.IsMeasureValid); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         private readonly LayoutQueue<ILayoutable> _toArrange = new LayoutQueue<ILayoutable>(v => !v.IsArrangeValid); 
														 | 
														
														 | 
														
															         private readonly LayoutQueue<ILayoutable> _toArrange = new LayoutQueue<ILayoutable>(v => !v.IsArrangeValid); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         private readonly Action _executeLayoutPass; 
														 | 
														
														 | 
														
															         private readonly Action _executeLayoutPass; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        private bool _disposed; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         private bool _queued; 
														 | 
														
														 | 
														
															         private bool _queued; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         private bool _running; 
														 | 
														
														 | 
														
															         private bool _running; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -33,6 +34,11 @@ namespace Avalonia.Layout 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             control = control ?? throw new ArgumentNullException(nameof(control)); 
														 | 
														
														 | 
														
															             control = control ?? throw new ArgumentNullException(nameof(control)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             Dispatcher.UIThread.VerifyAccess(); 
														 | 
														
														 | 
														
															             Dispatcher.UIThread.VerifyAccess(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            if (_disposed) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             if (!control.IsAttachedToVisualTree) 
														 | 
														
														 | 
														
															             if (!control.IsAttachedToVisualTree) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             { 
														 | 
														
														 | 
														
															             { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 #if DEBUG 
														 | 
														
														 | 
														
															 #if DEBUG 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -59,6 +65,11 @@ namespace Avalonia.Layout 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             control = control ?? throw new ArgumentNullException(nameof(control)); 
														 | 
														
														 | 
														
															             control = control ?? throw new ArgumentNullException(nameof(control)); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             Dispatcher.UIThread.VerifyAccess(); 
														 | 
														
														 | 
														
															             Dispatcher.UIThread.VerifyAccess(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            if (_disposed) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             if (!control.IsAttachedToVisualTree) 
														 | 
														
														 | 
														
															             if (!control.IsAttachedToVisualTree) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             { 
														 | 
														
														 | 
														
															             { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 #if DEBUG 
														 | 
														
														 | 
														
															 #if DEBUG 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -85,7 +96,7 @@ namespace Avalonia.Layout 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															             Dispatcher.UIThread.VerifyAccess(); 
														 | 
														
														 | 
														
															             Dispatcher.UIThread.VerifyAccess(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            if (!_owner.IsVisible) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            if (_disposed) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             { 
														 | 
														
														 | 
														
															             { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 return; 
														 | 
														
														 | 
														
															                 return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             } 
														 | 
														
														 | 
														
															             } 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -150,6 +161,11 @@ namespace Avalonia.Layout 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         /// <inheritdoc/> 
														 | 
														
														 | 
														
															         /// <inheritdoc/> 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         public virtual void ExecuteInitialLayoutPass() 
														 | 
														
														 | 
														
															         public virtual void ExecuteInitialLayoutPass() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         { 
														 | 
														
														 | 
														
															         { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            if (_disposed) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+                return; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             try 
														 | 
														
														 | 
														
															             try 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             { 
														 | 
														
														 | 
														
															             { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 _running = true; 
														 | 
														
														 | 
														
															                 _running = true; 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -179,6 +195,13 @@ namespace Avalonia.Layout 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             ExecuteInitialLayoutPass(); 
														 | 
														
														 | 
														
															             ExecuteInitialLayoutPass(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         } 
														 | 
														
														 | 
														
															         } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        public void Dispose() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            _disposed = true; 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            _toMeasure.Dispose(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            _toArrange.Dispose(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+        } 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         private void ExecuteMeasurePass() 
														 | 
														
														 | 
														
															         private void ExecuteMeasurePass() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         { 
														 | 
														
														 | 
														
															         { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             while (_toMeasure.Count > 0) 
														 | 
														
														 | 
														
															             while (_toMeasure.Count > 0) 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -256,7 +279,7 @@ namespace Avalonia.Layout 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															         private void QueueLayoutPass() 
														 | 
														
														 | 
														
															         private void QueueLayoutPass() 
														 | 
													
												
											
												
													
														| 
														 | 
														
															         { 
														 | 
														
														 | 
														
															         { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-            if (!_queued && !_running && _owner.IsVisible) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+            if (!_queued && !_running) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															             { 
														 | 
														
														 | 
														
															             { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 Dispatcher.UIThread.Post(_executeLayoutPass, DispatcherPriority.Layout); 
														 | 
														
														 | 
														
															                 Dispatcher.UIThread.Post(_executeLayoutPass, DispatcherPriority.Layout); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															                 _queued = true; 
														 | 
														
														 | 
														
															                 _queued = true; 
														 |