private void UpdateMargin(Grid container)
{
if (Math.Abs(RelativeLeftMargin - 0.5) <= double.Epsilon &&
Math.Abs(RelativeRightMargin - 0.5) <= double.Epsilon) return;
// apply Math.Round to avoid endless loops (Margin becomes rounded to screen pixels)
var width = container.ActualWidth;
container.Margin = new Thickness(
left: -Math.Round(width * (0.5 - RelativeLeftMargin)),
top: 0,
right: -Math.Round(width * (0.5 - RelativeRightMargin)),
bottom: 0);
}