How can I generate layout (XAML) programmatically?
Let say I have some kind of loop. And after each I want to generate this with the values I got:
<Grid Height="150" Name="grid1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Image Height="150" Name="image1" Stretch="Fill" Width="200" Grid.Column="1" Source="/Ilm;component/Images/testicon.png" HorizontalAlignment="Right" VerticalAlignment="Top" />
<TextBlock Height="51" Name="textBlock1" Text="Paris" Margin="12,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="40" />
<TextBlock FontSize="40" Height="51" HorizontalAlignment="Left" Margin="13,75,0,0" Name="textBlock2" Text="19°C" VerticalAlignment="Top" />
</Grid>
To add a new row to the grid, you will need to add a new row definition and then add the new controls. It will be similiar to the following logic:
You will need to put the properties that you want to set where I have the comment and also provided the correct row number (zero based).
To add the entire thing…
And that’s it. You’ll just need to fill in the properties I haven’t provided. Remember that your variable
parentControlwill be different. You haven’t provided what control you are adding these into, so it is unclear what that would be.