Skip to Content
Hidden WPF: Secrets for Creating Great Applications in Windows Presentation Foundation
book

Hidden WPF: Secrets for Creating Great Applications in Windows Presentation Foundation

by Alessandro Del Sole
February 2013
Beginner to intermediate
68 pages
1h 50m
English
Sams
Content preview from Hidden WPF: Secrets for Creating Great Applications in Windows Presentation Foundation

Visual Basic: Using XML Literals To Declare Controls

If you’re used to writing code in Visual Basic, you know that with XML Literals you can embed any kind of XML markup in your code; this rule includes XAML markup. For instance, you can declare a button as follows:

Dim testControl = <Button Width="100" Height="50" Name="Button1">Test</Button>

To make this line usable in the application, you need to import the XAML default namespaces:

Imports <xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/ presentation">Imports <xmlns:x ="http://schemas.microsoft.com/winfx/2006/xaml">

You can then easily parse the control definition by invoking the XamlReader.Parse method as follows:

Dim myButton = CType(System.Windows.Markup.    XamlReader.Parse(testControl.ToString), ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro WPF in C# 2010: Windows Presentation Foundation in .NET 4

Pro WPF in C# 2010: Windows Presentation Foundation in .NET 4

Matthew MacDonald
WPF in Action with Visual Studio 2008

WPF in Action with Visual Studio 2008

Arlen Feldman, Maxx Daymon

Publisher Resources

ISBN: 9780133432473