in ExampleGallery/TextLayouts.xaml.cs [240:291]
private void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
EnsureResources(sender, sender.Size);
currentDrawingSession = args.DrawingSession;
textLayout.SetBrush(0, testString.Length, null);
if (hasSelection)
{
int firstIndex = Math.Min(selectionStartIndex, selectionEndIndex);
int length = Math.Abs(selectionEndIndex - selectionStartIndex) + 1;
CanvasTextLayoutRegion[] descriptions = textLayout.GetCharacterRegions(firstIndex, length);
foreach (CanvasTextLayoutRegion description in descriptions)
{
args.DrawingSession.FillRectangle(InflateRect(description.LayoutBounds), Colors.White);
}
textLayout.SetBrush(firstIndex, length, selectionTextBrush);
}
EnsureInlineObjects();
EnsureTextDirection();
args.DrawingSession.DrawTextLayout(textLayout, 0, 0, textBrush);
if (ShowPerCharacterLayoutBounds)
{
for (int i = 0; i < testString.Length; i++)
{
CanvasTextLayoutRegion textLayoutRegion;
textLayout.GetCaretPosition(i, false, out textLayoutRegion);
args.DrawingSession.DrawRectangle(textLayoutRegion.LayoutBounds, Colors.Blue, 2);
}
}
if (ShowDrawBounds)
{
args.DrawingSession.DrawRectangle(textLayout.DrawBounds, Colors.Green, 2);
}
if (ShowLayoutBoundsWithTrailingWhitespace)
{
args.DrawingSession.DrawRectangle(textLayout.LayoutBoundsIncludingTrailingWhitespace, Colors.DarkRed, 2);
}
if (ShowLayoutBounds)
{
args.DrawingSession.DrawRectangle(textLayout.LayoutBounds, Colors.Red, 2, dashedStroke);
}
}