Skip to content

Commit

Permalink
ContentDialog restore height during resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nice3point committed Nov 19, 2023
1 parent 02fba95 commit cb06296
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
23 changes: 12 additions & 11 deletions RevitLookup.UI/Controls/ContentDialog/ContentDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
Expand All @@ -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);
}
Expand All @@ -698,9 +699,9 @@ private void ResizeWidth(UIElement element)

DialogWidth = DialogMaxWidth;
element.UpdateLayout();

DialogHeight = element.DesiredSize.Height;

if (DialogHeight > DialogMaxHeight)
{
DialogMaxHeight = DialogHeight;
Expand All @@ -715,9 +716,9 @@ private void ResizeHeight(UIElement element)

DialogHeight = DialogMaxHeight;
element.UpdateLayout();

DialogWidth = element.DesiredSize.Width;

if (DialogWidth > DialogMaxWidth)
{
DialogMaxWidth = DialogWidth;
Expand Down
1 change: 0 additions & 1 deletion RevitLookup.UI/Controls/ContentDialog/ContentDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
1 change: 0 additions & 1 deletion RevitLookup/Views/Dialogs/OpenSourceDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
<DataGrid
AutoGenerateColumns="False"
Expand Down

0 comments on commit cb06296

Please sign in to comment.