From abf866cf610025a6b8431e5ba2cdc527efcd4a71 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Fri, 7 Jul 2017 23:46:58 +0300 Subject: [PATCH] Fixes to get it working again after merge --- .../interop/WindowsInteropTest/EmbedToWpfDemo.xaml.cs | 3 ++- src/Avalonia.Diagnostics/DevTools.xaml.cs | 4 +--- src/Avalonia.Layout/IEmbeddedLayoutRoot.cs | 10 ++++++++++ src/Avalonia.Layout/LayoutManager.cs | 10 ++++------ .../Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs | 4 +++- 5 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 src/Avalonia.Layout/IEmbeddedLayoutRoot.cs diff --git a/samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml.cs b/samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml.cs index 636d89dc70..5ca2768d9e 100644 --- a/samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml.cs +++ b/samples/interop/WindowsInteropTest/EmbedToWpfDemo.xaml.cs @@ -27,11 +27,12 @@ namespace WindowsInteropTest { InitializeComponent(); var view = new MainView(); - Host.Content = view; + view.AttachedToVisualTree += delegate { view.AttachDevTools(); }; + Host.Content = view; var btn = (Avalonia.Controls.Button) RightBtn.Content; btn.Click += delegate { diff --git a/src/Avalonia.Diagnostics/DevTools.xaml.cs b/src/Avalonia.Diagnostics/DevTools.xaml.cs index e48cdf5681..85c3cfddd8 100644 --- a/src/Avalonia.Diagnostics/DevTools.xaml.cs +++ b/src/Avalonia.Diagnostics/DevTools.xaml.cs @@ -88,9 +88,7 @@ namespace Avalonia.Diagnostics { var devToolsWindow = (Window)sender; var devTools = (DevTools)devToolsWindow.Content; - var window = (Window)devTools.Root; - - s_open.Remove(window); + s_open.Remove((TopLevel)devTools.Root); _keySubscription.Dispose(); devToolsWindow.Closed -= DevToolsClosed; } diff --git a/src/Avalonia.Layout/IEmbeddedLayoutRoot.cs b/src/Avalonia.Layout/IEmbeddedLayoutRoot.cs new file mode 100644 index 0000000000..24f0ccd82e --- /dev/null +++ b/src/Avalonia.Layout/IEmbeddedLayoutRoot.cs @@ -0,0 +1,10 @@ +namespace Avalonia.Layout +{ + /// + /// A special layout root with enforced size for Arrange pass + /// + public interface IEmbeddedLayoutRoot : ILayoutRoot + { + Size AllocatedSize { get; } + } +} \ No newline at end of file diff --git a/src/Avalonia.Layout/LayoutManager.cs b/src/Avalonia.Layout/LayoutManager.cs index 0ff417e791..108922b5b9 100644 --- a/src/Avalonia.Layout/LayoutManager.cs +++ b/src/Avalonia.Layout/LayoutManager.cs @@ -186,14 +186,12 @@ namespace Avalonia.Layout if (!control.IsArrangeValid && control.IsAttachedToVisualTree) { - if (control is ILayoutRoot root) - { - root.Arrange(new Rect(root.ClientSize)); - } + if (control is IEmbeddedLayoutRoot embeddedRoot) + control.Arrange(new Rect(embeddedRoot.AllocatedSize)); + else if (control is ILayoutRoot root) + control.Arrange(new Rect(root.DesiredSize)); else - { control.Arrange(control.PreviousArrange.Value); - } } } diff --git a/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs b/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs index c990bb708e..229e330a33 100644 --- a/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs +++ b/src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs @@ -33,7 +33,7 @@ namespace Avalonia.Win32.Interop.Wpf public EmbeddableControlRoot ControlRoot { get; } internal ImageSource ImageSource { get; set; } - public class CustomControlRoot : EmbeddableControlRoot + public class CustomControlRoot : EmbeddableControlRoot, IEmbeddedLayoutRoot { public CustomControlRoot(WpfTopLevelImpl impl) : base(impl) { @@ -52,6 +52,8 @@ namespace Avalonia.Win32.Interop.Wpf LayoutManager.Instance.ExecuteLayoutPass(); Renderer?.Resized(clientSize); } + + public Size AllocatedSize => ClientSize; } public WpfTopLevelImpl()