private static SizeChangedEventHandler SetupAndOpenDialog(CushWindow window, DialogBase dialog) { dialog.SetValue(Panel.ZIndexProperty, (int) window.OverlayBox.GetValue(Panel.ZIndexProperty) + 1); dialog.MinHeight = window.ActualHeight/4.0; dialog.MaxHeight = window.ActualHeight; //an event handler for auto resizing an open dialog. SizeChangedEventHandler sizeHandler = (sender, args) => { dialog.MinHeight = window.ActualHeight/4.0; dialog.MaxHeight = window.ActualHeight; }; window.SizeChanged += sizeHandler; if (!window.DialogContainer.Children.Contains(dialog)) { window.DialogContainer.Children.Add(dialog); //add the dialog to the container } dialog.OnShown(); return sizeHandler; }