Browse Source

[TEMP] Call measure directly

pull/1016/head
Nikita Tsukanov 9 years ago
parent
commit
df13ab2ecb
  1. 12
      src/Avalonia.Controls/Embedding/EmbeddableControlRoot.cs
  2. 16
      src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs

12
src/Avalonia.Controls/Embedding/EmbeddableControlRoot.cs

@ -22,6 +22,8 @@ namespace Avalonia.Controls.Embedding
[CanBeNull] [CanBeNull]
public new IEmbeddableWindowImpl PlatformImpl => (IEmbeddableWindowImpl) base.PlatformImpl; public new IEmbeddableWindowImpl PlatformImpl => (IEmbeddableWindowImpl) base.PlatformImpl;
protected bool EnforceClientSize { get; set; } = true;
public void Prepare() public void Prepare()
{ {
EnsureInitialized(); EnsureInitialized();
@ -38,14 +40,12 @@ namespace Avalonia.Controls.Embedding
init.EndInit(); init.EndInit();
} }
} }
public Size MeasureBase(Size availableSize) => base.MeasureOverride(availableSize);
protected override Size MeasureOverride(Size availableSize) protected override Size MeasureOverride(Size availableSize)
{ {
var cs = PlatformImpl?.ClientSize ?? default(Size); if (EnforceClientSize)
base.MeasureOverride(cs); availableSize = PlatformImpl?.ClientSize ?? default(Size);
return cs; return base.MeasureOverride(availableSize);
} }
private readonly NameScope _nameScope = new NameScope(); private readonly NameScope _nameScope = new NameScope();

16
src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs

@ -35,10 +35,16 @@ namespace Avalonia.Win32.Interop.Wpf
public class CustomControlRoot : EmbeddableControlRoot public class CustomControlRoot : EmbeddableControlRoot
{ {
public CustomControlRoot()
{
EnforceClientSize = false;
}
public override void InvalidateMeasure() public override void InvalidateMeasure()
{ {
base.InvalidateMeasure();
((FrameworkElement)PlatformImpl)?.InvalidateMeasure(); ((FrameworkElement)PlatformImpl)?.InvalidateMeasure();
base.InvalidateMeasure();
} }
} }
@ -95,10 +101,16 @@ namespace Avalonia.Win32.Interop.Wpf
return base.ArrangeOverride(finalSize); 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) protected override void OnRender(DrawingContext drawingContext)
{ {
if(ActualHeight == 0 || ActualWidth == 0)
return;
_ttl.Paint?.Invoke(new Rect(0, 0, ActualWidth, ActualHeight)); _ttl.Paint?.Invoke(new Rect(0, 0, ActualWidth, ActualHeight));
if (ImageSource != null) if (ImageSource != null)
drawingContext.DrawImage(ImageSource, new System.Windows.Rect(0, 0, ActualWidth, ActualHeight)); drawingContext.DrawImage(ImageSource, new System.Windows.Rect(0, 0, ActualWidth, ActualHeight));

Loading…
Cancel
Save