private static void UpdateMargin(TextBlock textBlock, TextLineModes mode, Thickness margin)
        {
            if (textBlock.ActualHeight == 0)
            {
                textBlock.TextLineBounds = TextLineBounds.Tight;

                // Unfortunately, we won't know the TextBlock's height until after load
                textBlock.Loaded += textBlock_Loaded;
                return;
            }

            Thickness currentMargin = textBlock.Margin;

            if (mode == TextLineModes.Baseline)
            {
                currentMargin.Bottom = margin.Bottom;
                currentMargin.Top    = margin.Top - textBlock.ActualHeight;
            }
            else if (mode == TextLineModes.CapHeight)
            {
                currentMargin.Top    = margin.Top;
                currentMargin.Bottom = margin.Bottom - textBlock.ActualHeight;
            }

            currentMargin.Left  = margin.Left;
            currentMargin.Right = margin.Right;

            textBlock.Margin = currentMargin;
        }
 public static void SetMode(DependencyObject d, TextLineModes value)
 {
     d.SetValue(ModeProperty, value);
 }