diff --git a/src/Avalonia.Controls/Embedding/EmbeddableControlRoot.cs b/src/Avalonia.Controls/Embedding/EmbeddableControlRoot.cs index 45b4f8eaa1..179dccaf76 100644 --- a/src/Avalonia.Controls/Embedding/EmbeddableControlRoot.cs +++ b/src/Avalonia.Controls/Embedding/EmbeddableControlRoot.cs @@ -22,6 +22,8 @@ namespace Avalonia.Controls.Embedding [CanBeNull] public new IEmbeddableWindowImpl PlatformImpl => (IEmbeddableWindowImpl) base.PlatformImpl; + protected bool EnforceClientSize { get; set; } = true; + public void Prepare() { EnsureInitialized(); @@ -38,14 +40,12 @@ namespace Avalonia.Controls.Embedding init.EndInit(); } } - - public Size MeasureBase(Size availableSize) => base.MeasureOverride(availableSize); - + protected override Size MeasureOverride(Size availableSize) { - var cs = PlatformImpl?.ClientSize ?? default(Size); - base.MeasureOverride(cs); - return cs; + if (EnforceClientSize) + availableSize = PlatformImpl?.ClientSize ?? default(Size); + return base.MeasureOverride(availableSize); } private readonly NameScope _nameScope = new NameScope(); diff --git a/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs b/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs index 7be6b7e800..b74358ec4d 100644 --- a/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs +++ b/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs @@ -35,10 +35,16 @@ namespace Avalonia.Win32.Interop.Wpf public class CustomControlRoot : EmbeddableControlRoot { + public CustomControlRoot() + { + EnforceClientSize = false; + + } + public override void InvalidateMeasure() { - base.InvalidateMeasure(); ((FrameworkElement)PlatformImpl)?.InvalidateMeasure(); + base.InvalidateMeasure(); } } @@ -95,10 +101,16 @@ namespace Avalonia.Win32.Interop.Wpf return base.ArrangeOverride(finalSize); } - protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize) => ControlRoot.MeasureBase(availableSize.ToAvaloniaSize()).ToWpfSize(); + protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize) + { + ControlRoot.Measure(availableSize.ToAvaloniaSize()); + return ControlRoot.DesiredSize.ToWpfSize(); + } protected override void OnRender(DrawingContext drawingContext) { + if(ActualHeight == 0 || ActualWidth == 0) + return; _ttl.Paint?.Invoke(new Rect(0, 0, ActualWidth, ActualHeight)); if (ImageSource != null) drawingContext.DrawImage(ImageSource, new System.Windows.Rect(0, 0, ActualWidth, ActualHeight));