Silverlight call XAML at Runtime in VB.NET

In this article you will learn how to call an XAML at the runtime in silverlight.
  • 2307

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

<UserControl x:Class="SilverlightApplication6.MainPage"

    <Grid x:Name="LayoutRoot" Background="White" Margin="10">
        <StackPanel Orientation="Vertical">
            <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" />

MainPage.xaml.vb Code

Imports System.Collections.Generic
Imports System.Linq
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports System.Windows.Markup

Partial Public Class MainPage
    Inherits UserControl
    Public Sub New()
    End Sub
    Private Sub Button_Click(ByVal sender As ObjectByVal e As RoutedEventArgs)
        Dim xaml As String = "<Rectangle xmlns="""" Height=""160"" Width=""120"" Fill=""Black"" />"
        Dim rectangle As Rectangle = DirectCast(XamlReader.Load(xaml), Rectangle)
End Class

Output Window



Hope you will learn through this article how you can call an XAML at runtime in silverlight.


More Articles

© 2020 DotNetHeaven. All rights reserved.