diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs
index 7fed712e07..893859b915 100644
--- a/src/Avalonia.Controls/Window.cs
+++ b/src/Avalonia.Controls/Window.cs
@@ -19,27 +19,28 @@ namespace Avalonia.Controls
///
/// Determines how a will size itself to fit its content.
///
+ [Flags]
public enum SizeToContent
{
///
/// The window will not automatically size itself to fit its content.
///
- Manual,
+ Manual = 0,
///
/// The window will size itself horizontally to fit its content.
///
- Width,
+ Width = 1,
///
/// The window will size itself vertically to fit its content.
///
- Height,
+ Height = 2,
///
/// The window will size itself horizontally and vertically to fit its content.
///
- WidthAndHeight,
+ WidthAndHeight = 3,
}
///
@@ -374,27 +375,31 @@ namespace Avalonia.Controls
{
var sizeToContent = SizeToContent;
var clientSize = ClientSize;
- Size constraint;
+ Size constraint = clientSize;
- switch (sizeToContent)
+ if ((sizeToContent & SizeToContent.Width) != 0)
{
- case SizeToContent.Width:
- constraint = new Size(double.PositiveInfinity, ClientSize.Height);
- break;
- case SizeToContent.Height:
- constraint = new Size(ClientSize.Width, double.PositiveInfinity);
- break;
- case SizeToContent.WidthAndHeight:
- constraint = Size.Infinity;
- break;
- case SizeToContent.Manual:
- constraint = ClientSize;
- break;
- default:
- throw new InvalidOperationException("Invalid value for SizeToContent.");
+ constraint = constraint.WithWidth(double.PositiveInfinity);
}
- return base.MeasureOverride(constraint);
+ if ((sizeToContent & SizeToContent.Height) != 0)
+ {
+ constraint = constraint.WithHeight(double.PositiveInfinity);
+ }
+
+ var result = base.MeasureOverride(constraint);
+
+ if ((sizeToContent & SizeToContent.Width) == 0)
+ {
+ result = result.WithWidth(clientSize.Width);
+ }
+
+ if ((sizeToContent & SizeToContent.Height) == 0)
+ {
+ result = result.WithHeight(clientSize.Height);
+ }
+
+ return result;
}
protected override void HandleClosed()
diff --git a/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs b/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
index c4febff434..f5893ae69a 100644
--- a/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
+++ b/src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
@@ -140,6 +140,7 @@ namespace Avalonia.DesignerSupport.Remote
BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (builderMethod == null)
throw Die($"{entryPoint.DeclaringType.FullName} doesn't have a method named {BuilderMethodName}");
+ Design.IsDesignMode = true;
Log($"Obtaining AppBuilder instance from {builderMethod.DeclaringType.FullName}.{builderMethod.Name}");
var appBuilder = builderMethod.Invoke(null, null);
Log($"Initializing application in design mode");