Silverlight call XAML at Runtime in VB.NET
In this article you will learn how to call an XAML at the runtime in silverlight.
XAML: It can initialize objects and set properties of objects, using a language structure that shows hierarchical relationships between multiple objects, and using a backing type convention that supports extension of types, it is basically embedded in your HTML pages and the Silverlight plug-in allows you to render the XAML objects onto to your page. Silverlight and XAML integrate seamlessly together. Every XAML element can be accessed or manipulated from the same client side JS that would interact with any HTML elements.
A XAML file always has exactly one element serving as its root, which declares an object that will be the conceptual root of some programming structure such as a page, or the object graph of the entire run-time definition of an application.
I will given an simple example that shows you that you can also call an XAML at the runtime:
Example of XAML
<Grid x:Name="LayoutRoot" Background="White" Margin="10">
<Canvas x:Name="Canvas" Height="321">
<Button x:Name="Button" Content="Click to Create Rectangle" Height="30"Width="189" Click="Button_Click" Canvas.Left="216" Canvas.Top="0" />
Partial Public Class MainPage
Public Sub New()
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim xaml As String = "<Rectangle xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" Height=""160"" Width=""120"" Fill=""Black"" />"
Dim rectangle As Rectangle = DirectCast(XamlReader.Load(xaml), Rectangle)
Hope you will learn through this article how you can call an XAML at runtime in silverlight.