I want to achieve this in WinRT app.
I know I can use SharpDX to render the text, you can check out my CodeProject article. I want to know how to create a white background image of size with capacity to accommodate the text with font-family Segoe UI and font size of 16?
I've found how to create white image. But how can I calculate the size of the long string (like 2000+ characters), which is going to be render on white image ?
I've checked how to calculate the textbock height and width in on load if i create textblock from code?, but I am getting incorrect value. I don't know what to pass as arguments in Arrange(...)
& Measure(...)
methods. I am passing Window.Current.Bounds
as parameter. I want something like this.
private double GetHeight(string Text, string fontFamily, double fontSize)
{
//TODO:
}
UPDATE 1
According to Filip's suggestion I tried this, but it's also giving me incorrect value.
TextBlock textBlock = new TextBlock();
private double GetHeight(string Text)
{
var scroller = new ScrollViewer();
scroller.Height = Window.Current.Bounds.Height;
scroller.Width = Window.Current.Bounds.Width;
scroller.Content = textBlock;
textBlock.Text = Text;
textBlock.FontFamily = new FontFamily("Segoe UI");
textBlock.FontSize = 40;
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Arrange(new Rect(0, 0, 9000000000, 9000000000));
textBlock.Measure(new Size(9000000000, 9000000000));
root.Children.Add(scroller);
return textBlock.ActualHeight; //return 478.82919311523437
}
// root is the Root grid of the app, there's nothing in XAML
private void root_Tapped_1(object sender, TappedRoutedEventArgs e)
{
var aa = textBlock.ActualHeight; //return 2766.5732421875
}