diff --git a/src/Eto.Wpf/Forms/PixelLayoutHandler.cs b/src/Eto.Wpf/Forms/PixelLayoutHandler.cs old mode 100644 new mode 100755 index 43e3264f9..8184dde66 --- a/src/Eto.Wpf/Forms/PixelLayoutHandler.cs +++ b/src/Eto.Wpf/Forms/PixelLayoutHandler.cs @@ -56,7 +56,7 @@ public void Add(Control child, int x, int y) swc.Canvas.SetLeft(element, x); swc.Canvas.SetTop(element, y); Control.Children.Add(element); - UpdatePreferredSize(); + OnChildPreferredSizeUpdated(); } public void Move(Control child, int x, int y) @@ -64,20 +64,20 @@ public void Move(Control child, int x, int y) var element = child.GetContainerControl(); swc.Canvas.SetLeft(element, x); swc.Canvas.SetTop(element, y); - UpdatePreferredSize(); + OnChildPreferredSizeUpdated(); } public void Remove(Control child) { var element = child.GetContainerControl(); Control.Children.Remove(element); - UpdatePreferredSize(); + OnChildPreferredSizeUpdated(); } public override void Remove(sw.FrameworkElement child) { Control.Children.Remove(child); - UpdatePreferredSize(); + OnChildPreferredSizeUpdated(); } int suspended; diff --git a/src/Eto.Wpf/Forms/TableLayoutHandler.cs b/src/Eto.Wpf/Forms/TableLayoutHandler.cs old mode 100644 new mode 100755 index 2ac02725d..9495f6630 --- a/src/Eto.Wpf/Forms/TableLayoutHandler.cs +++ b/src/Eto.Wpf/Forms/TableLayoutHandler.cs @@ -395,7 +395,7 @@ public void Add(Control child, int x, int y) } Control.Children.Add(control); } - UpdatePreferredSize(); + OnChildPreferredSizeUpdated(); } public void Move(Control child, int x, int y) @@ -420,7 +420,7 @@ public void Move(Control child, int x, int y) SetScale(handler, x, y); } controls[x, y] = child; - UpdatePreferredSize(); + OnChildPreferredSizeUpdated(); } public void Remove(Control child) @@ -434,7 +434,7 @@ public override void Remove(sw.FrameworkElement child) var y = swc.Grid.GetRow(child); Control.Children.Remove(child); controls[x, y] = null; - UpdatePreferredSize(); + OnChildPreferredSizeUpdated(); } } } diff --git a/src/Eto.Wpf/Forms/WpfContainer.cs b/src/Eto.Wpf/Forms/WpfContainer.cs old mode 100644 new mode 100755 index 2750d3bbd..919b8f0ad --- a/src/Eto.Wpf/Forms/WpfContainer.cs +++ b/src/Eto.Wpf/Forms/WpfContainer.cs @@ -12,7 +12,7 @@ public interface IWpfContainer { void Remove(sw.FrameworkElement child); - void UpdatePreferredSize(); + void OnChildPreferredSizeUpdated(); } public abstract class WpfContainer : WpfFrameworkElement, Container.IHandler, IWpfContainer diff --git a/src/Eto.Wpf/Forms/WpfFrameworkElement.cs b/src/Eto.Wpf/Forms/WpfFrameworkElement.cs index fd2c414ec..379bb6c24 100755 --- a/src/Eto.Wpf/Forms/WpfFrameworkElement.cs +++ b/src/Eto.Wpf/Forms/WpfFrameworkElement.cs @@ -252,10 +252,16 @@ public virtual void UpdatePreferredSize() { if (Widget.Loaded) { - Widget.VisualParent.GetWpfContainer()?.UpdatePreferredSize(); + Widget.VisualParent.GetWpfContainer()?.OnChildPreferredSizeUpdated(); } } + public virtual void OnChildPreferredSizeUpdated() + { + if (double.IsNaN(UserPreferredSize.Width) || double.IsNaN(UserPreferredSize.Height)) + UpdatePreferredSize(); + } + public virtual void SetScale(bool xscale, bool yscale) { XScale = xscale; diff --git a/src/Eto.Wpf/Forms/WpfPanel.cs b/src/Eto.Wpf/Forms/WpfPanel.cs old mode 100644 new mode 100755 index 7775970d5..7eec69561 --- a/src/Eto.Wpf/Forms/WpfPanel.cs +++ b/src/Eto.Wpf/Forms/WpfPanel.cs @@ -113,7 +113,7 @@ public Control Content else border.Child = null; Control.InvalidateMeasure(); - UpdatePreferredSize(); + OnChildPreferredSizeUpdated(); } } @@ -125,7 +125,7 @@ public override void Remove(sw.FrameworkElement child) { content = null; border.Child = null; - UpdatePreferredSize(); + OnChildPreferredSizeUpdated(); } } }