Reputation: 417
I am creating a Windows 8 app using C#. In one of the pages I need to display a random sentence with each word having a different color. I want to do it dynamically and not using the .xaml file. Is there a way to dynamically add text blocks for this? Any other approach is also welcome.
Thanks.
Upvotes: 1
Views: 665
Reputation: 588
It's easy to create controls programatically in the codebehind, an example inventing names:
TextBlock colorText = new TextBlock();
colortext.Foreground= new SolidColorBrush(Colors.Yellow);
this.Panel.Children.Add(colortext)
Upvotes: 3