From cb06296699c0abd09f313d9eadd0a2973fe2d175 Mon Sep 17 00:00:00 2001 From: Nice3point Date: Sun, 19 Nov 2023 03:03:35 +0300 Subject: [PATCH] ContentDialog restore height during resizing --- .../Controls/ContentDialog/ContentDialog.cs | 23 ++++++++++--------- .../Controls/ContentDialog/ContentDialog.xaml | 1 - .../Views/Dialogs/OpenSourceDialog.xaml | 1 - 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/RevitLookup.UI/Controls/ContentDialog/ContentDialog.cs b/RevitLookup.UI/Controls/ContentDialog/ContentDialog.cs index aa2377c2a..da4bba791 100644 --- a/RevitLookup.UI/Controls/ContentDialog/ContentDialog.cs +++ b/RevitLookup.UI/Controls/ContentDialog/ContentDialog.cs @@ -649,19 +649,19 @@ protected virtual void OnButtonClick(ContentDialogButton button) protected override Size MeasureOverride(Size availableSize) { var rootElement = (UIElement)GetVisualChild(0)!; - + rootElement.Measure(availableSize); Size desiredSize = rootElement.DesiredSize; - + Size newSize = GetNewDialogSize(desiredSize); - + DialogHeight = newSize.Height; DialogWidth = newSize.Width; - + ResizeWidth(rootElement); ResizeHeight(rootElement); - - return desiredSize; + + return availableSize; } /// @@ -681,12 +681,13 @@ protected virtual void OnLoaded() private Size GetNewDialogSize(Size desiredSize) { var paddingWidth = Padding.Left + Padding.Right; + var paddingHeight = Padding.Top + Padding.Bottom; var marginHeight = DialogMargin.Bottom + DialogMargin.Top; var marginWidth = DialogMargin.Left + DialogMargin.Right; var width = desiredSize.Width - marginWidth + paddingWidth; - var height = desiredSize.Height - marginHeight; + var height = desiredSize.Height - marginHeight + paddingHeight; return new Size(width, height); } @@ -698,9 +699,9 @@ private void ResizeWidth(UIElement element) DialogWidth = DialogMaxWidth; element.UpdateLayout(); - + DialogHeight = element.DesiredSize.Height; - + if (DialogHeight > DialogMaxHeight) { DialogMaxHeight = DialogHeight; @@ -715,9 +716,9 @@ private void ResizeHeight(UIElement element) DialogHeight = DialogMaxHeight; element.UpdateLayout(); - + DialogWidth = element.DesiredSize.Width; - + if (DialogWidth > DialogMaxWidth) { DialogMaxWidth = DialogWidth; diff --git a/RevitLookup.UI/Controls/ContentDialog/ContentDialog.xaml b/RevitLookup.UI/Controls/ContentDialog/ContentDialog.xaml index b4bff4f0e..041123132 100644 --- a/RevitLookup.UI/Controls/ContentDialog/ContentDialog.xaml +++ b/RevitLookup.UI/Controls/ContentDialog/ContentDialog.xaml @@ -87,7 +87,6 @@ x:Name="PART_ContentScroll" Grid.Row="1" Margin="0,20" - Padding="0,0,12,0" CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}" HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" diff --git a/RevitLookup/Views/Dialogs/OpenSourceDialog.xaml b/RevitLookup/Views/Dialogs/OpenSourceDialog.xaml index d343ea7f8..dd7f18db7 100644 --- a/RevitLookup/Views/Dialogs/OpenSourceDialog.xaml +++ b/RevitLookup/Views/Dialogs/OpenSourceDialog.xaml @@ -7,7 +7,6 @@ xmlns:dialogs="clr-namespace:RevitLookup.ViewModels.Dialogs" xmlns:rl="http://revitlookup.com/xaml" mc:Ignorable="d" - MinWidth="150" d:DataContext="{d:DesignInstance dialogs:OpenSourceViewModel}">