Browse Source

WPF integration improvements

Nikita Tsukanov 8 years ago
parent
commit
d06c9e04ed

+ 1 - 0
src/Windows/Avalonia.Win32.Interop/Wpf/WpfAvaloniaHost.cs

@@ -29,6 +29,7 @@ namespace Avalonia.Win32.Interop.Wpf
             _impl.Visibility = Visibility.Visible;
             AddLogicalChild(_impl);
             AddVisualChild(_impl);
+            SnapsToDevicePixels = true;
         }
 
         public object Content

+ 9 - 2
src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs

@@ -54,6 +54,10 @@ namespace Avalonia.Win32.Interop.Wpf
             ControlRoot = new EmbeddableControlRoot(this);
             SnapsToDevicePixels = true;
             Focusable = true;
+            DataContextChanged += delegate
+            {
+                ControlRoot.DataContext = DataContext;
+            };
         }
 
         private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
@@ -80,15 +84,18 @@ namespace Avalonia.Win32.Interop.Wpf
 
         IEnumerable<object> ITopLevelImpl.Surfaces => _surfaces;
 
+        private Size _previousSize;
         protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize)
         {
             _finalSize = finalSize.ToAvaloniaSize();
+            if (_finalSize == _previousSize)
+                return finalSize;
+            _previousSize = _finalSize;
             _ttl.Resized?.Invoke(finalSize.ToAvaloniaSize());
             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.MeasureBase(availableSize.ToAvaloniaSize()).ToWpfSize();
 
         protected override void OnRender(DrawingContext drawingContext)
         {