How to create runtime dynamic controls such as :
TextBlock Text_Sample= new TextBlock();
Text_Sample.Text = "SAMPLE Textblock";
//Until here is ok
//Now we need something like:
this.Controls.Add(Text_Sample);
Code: Select all
<Page
x:Class="Application2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Application2"
xmlns:src="using:UserControlsTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel x:Name="stackPanel1">
</StackPanel>
</Page>
Code: Select all
namespace Application2
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
TextBlock myTextBlock = new TextBlock() { Text = "Hello World" };
stackPanel1.Children.Add(myTextBlock);
}
}
}
Users browsing this forum: No registered users and 53 guests