You can set up a TextBlock control in code, set the Text property with the string, and call the Render() method of the WritableBitmap with that TextBlock. The TextBlock never has to be on the visual tree, but you will have to call Invalidate() on the bitmap after to get the text to show up.
private void RenderString(WriteableBitmap bitmap, string stringToRender)
{
TextBlock textBlock = new TextBlock();
textBlock.Text = stringToRender;
// set font, size, etc. on textBlock
bitmap.Render(textBlock, null);
bitmap.Invalidate();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…