UnhandledThreadException, Exception='System.ArgumentException: Height must be non-negative.
at System.Windows.Rect.set_Height(Double value)
at Divelements.SandDock.DockSite.ArrangeOverride(Size arrangeBounds)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.DockPanel.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize)
at System.Windows.Controls.ContentPresenter.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Border.ArrangeOverride(Size finalSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.DockPanel.ArrangeOverride(Size arrangeSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Controls.Decorator.ArrangeOverride(Size arrangeSize)
at System.Windows.Documents.AdornerDecorator.ArrangeOverride(Size finalSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.Interop.HwndSource.Process_WM_SIZE(UIElement rootUIElement, IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Interop.HwndSource.LayoutFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.SafeNativeMethods.SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, Int32 x, Int32 y, Int32 cx, Int32 cy, Int32 flags)
at System.Windows.Forms.Integration.ElementHost.SetHWndSourceWindowPos()
at System.Windows.Forms.Integration.ElementHost.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)'
To give you about the scenario, this haapens with a window hosted inside a windows forms, and we are trying to force auto-sizing feature over a DockableWindow whoose child is a usercontrol using wrappanel for its layout. when the wrappanel wraps around changing the height of the usercontrol, we are doing something as following.
CustomDockableWindow.cs class composes of a DockableWindow _dockableWindow and has the following method to force the height of dockablewindow to the given value.
private void ForceHeight(double value)
{
if (double.IsNaN(value) || _window.DockSite.ActualHeight <= value)
{
// Height shouldn't be greater than the DockSite's Height or double.NaN:
throw new ArgumentOutOfRangeException("MinHeight", value, string.Format("Range is from 0 to {0}.", _window.DockSite.ActualHeight));
}
// returns a struct with the SpiltContainer and WindowGroup of the
_window by traversiing the DockSite layout and locating the window in
the layout.
DockableWindowPropertycontainer windowPropertyContainer = GetDockableWindowProperties(_window);
if (windowPropertyContainer.SplitContainer != null && windowPropertyContainer.WindowGroup!= null )
{
double newHeight = Math.Max(value, 0);
if (windowPropertyContainer.WindowGroup.Pinned)
{
SplitContainer splitContainer = windowPropertyContainer.SplitContainer;
while (splitContainer.Parent is SplitContainer)
{
splitContainer = (SplitContainer)splitContainer.Parent;
}
splitContainer.SetValue(DockSite.ContentSizeProperty, newHeight);
}
else
{
_window.ContentSize = newHeight;
}
}
}
The above is triggered on a SizeChanged of the DockableWindow and we recalculate the height required when the wrappanel shrinks/expands.
This is working most off the time but when other windows are docked above or below this window, sometimes it crashes with the stacktrace as given above.
Kindly advise how to get around this issue or if there is a better way to force the size of a particular window which would maintain the size of a particular window at the required level but could affect the layout of other windows (accpetable in our case)