From d5d226601e0118c34533cb6da0324e9e65c94809 Mon Sep 17 00:00:00 2001 From: Yimeng Wu Date: Fri, 18 Dec 2020 00:16:04 +0800 Subject: [PATCH] Fix #222: ContentDialog is not centered when MaxWidth/MaxHeight not set --- ModernWpf.Controls/ContentDialog/ContentDialog.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ModernWpf.Controls/ContentDialog/ContentDialog.cs b/ModernWpf.Controls/ContentDialog/ContentDialog.cs index 9b62012c..e099c2d7 100644 --- a/ModernWpf.Controls/ContentDialog/ContentDialog.cs +++ b/ModernWpf.Controls/ContentDialog/ContentDialog.cs @@ -1163,12 +1163,15 @@ protected override Visual GetVisualChild(int index) protected override Size MeasureOverride(Size constraint) { + var desiredSize = AdornedElement.RenderSize; + constraint = desiredSize; Child?.Measure(constraint); - return constraint; + return desiredSize; } - protected override Size ArrangeOverride(Size finalSize) + protected override Size ArrangeOverride(Size size) { + var finalSize = base.ArrangeOverride(size); Child?.Arrange(new Rect(new Point(), finalSize)); return finalSize; }