private static void OnBoundsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is FrameworkElement)
{
FrameworkElement element = (FrameworkElement)d;
LayerContainer parent = element.Parent as LayerContainer;
if ((parent != null) && (parent.Layer is ElementsLayer))
{
Rectangle2D oldValue = (Rectangle2D)e.OldValue;
Rectangle2D newValue = (Rectangle2D)e.NewValue;
if (newValue.IsEmpty)
{
element.Visibility = Visibility.Collapsed;
}
else if (!oldValue.IsEmpty && oldValue.Width == newValue.Width && oldValue.Height == newValue.Height)
{
parent.InvalidateArrange();
}
else
{
parent.InvalidateMeasure();
}
}
}
}