private void UpdateChildLocationsAfterSizeChange(SizeInfo newSizeInfo) { foreach (UIElement uiElement in Children) { if (newSizeInfo.WidthChanged) { var relativeX = (double)uiElement.GetValue(HorizontalProportionProperty); if (!double.IsInfinity(relativeX)) { var newX = relativeX * newSizeInfo.Size.Width; SetLeftOfRelativePoint(uiElement, newX); } } if (newSizeInfo.HeightChanged) { var relativeY = (double)uiElement.GetValue(VerticalProportionProperty); if (!double.IsInfinity(relativeY)) { var newY = relativeY * newSizeInfo.Size.Height; SetTopOfRelativePoint(uiElement, newY); } } } }
void OnLoaded(object sender, RoutedEventArgs e) { if (firstLoad) { foreach (UIElement child in Children) { UpdateHorizontalProportions(child); UpdateVerticalProportions(child); } firstLoad = false; } else { var newSizeInfo = new SizeInfo(new Size(ActualWidth, ActualHeight)) { WidthChanged = true, HeightChanged = true }; UpdateChildLocationsAfterSizeChange(newSizeInfo); } SizeChanged += OnSizeChanged; }