Dim contacts = <Contacts>
<Contact1>
<Name>Patrick Hines</Name>
<Phone>206-555-0144</Phone>
<Address>
<Street1>123 Main St</Street1>
<City>Mercer Island</City>
<State>WA</State>
<Postal>68042</Postal>
</Address>
</Contact1>
<Contact2>
<Name>Yoshi Latime</Name>
<Phone>503-555-6874</Phone>
<Address>
<Street1>City Center Plaza 516 Main St.</Street1>
<City>Elgin</City>
<State>OR</State>
<Postal>97827</Postal>
</Address>
</Contact2>
</Contacts>
' Create the first TextBlock control.
' Note that the element has to declare two XAML namespaces.
Dim textBlock1 = <TextBlock
xmlns='http://schemas.microsoft.com/client/2007'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
TextWrapping='Wrap'
Width='400'
Canvas.Top='10'
Text=''/>
' Get the first child element from contacts xml tree.
Dim contact1 As XElement = contacts.Element("Contact1")
' Set the value of the "Text" attribute
' to the content of the first contact in the contacts xml tree.
textBlock1.Attribute("Text").SetValue(contact1.ToString())
' Get the second child element from contacts xml tree.
Dim contact2 As XElement = contacts.Element("Contact2")
' Create the second TextBlock control.
' Note that the element has to declare two XAML namespaces.
Dim textBlock2 = <TextBlock
xmlns='http://schemas.microsoft.com/client/2007'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
Width='600'
Canvas.Top='250'
Text=<%= contact2.ToString() %>/>
' Add TextBlock control to the page
LayoutRoot.Children.Add(CType(XamlReader.Load(textBlock1.ToString()), UIElement))
' Add TextBlock control to the page
LayoutRoot.Children.Add(CType(XamlReader.Load(textBlock2.ToString()), UIElement))
// Populate XElement contacts with Contacts information.
XElement contacts =
new XElement("Contacts",
new XElement("Contact1",
new XElement("Name", "Patrick Hines"),
new XElement("Phone", "206-555-0144"),
new XElement("Address",
new XElement("Street1", "123 Main St"),
new XElement("City", "Mercer Island"),
new XElement("State", "WA"),
new XElement("Postal", "68042")
)
),
new XElement("Contact2",
new XElement("Name", "Yoshi Latime"),
new XElement("Phone", "503-555-6874"),
new XElement("Address",
new XElement("Street1", "City Center Plaza 516 Main St."),
new XElement("City", "Elgin"),
new XElement("State", "OR"),
new XElement("Postal", "97827")
)
)
);
// Create the first TextBlock control.
// Note that the element has to declare two XAML namespaces.
XElement textBlock1 = XElement.Parse(
@"<TextBlock
xmlns='http://schemas.microsoft.com/client/2007'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
TextWrapping= 'Wrap'
Width = '400'
Canvas.Top = '10'
Text=''/>");
// Get the first child element from contacts xml tree.
XElement contact1 = contacts.Element("Contact1");
// Set the value of the last attribute "Text"
// to the content of contacts xml tree.
textBlock1.LastAttribute.SetValue(contact1.ToString());
// Get the second child element from contacts xml tree.
XElement contact2 = contacts.Element("Contact2");
// Create the second TextBlock control.
// Note that the element has to declare two XAML namespaces.
XNamespace xmlns = "http://schemas.microsoft.com/client/2007";
XElement textBlock2 = new XElement(xmlns + "TextBlock",
new XAttribute(XNamespace.Xmlns + "x", "http://schemas.microsoft.com/winfx/2006/xaml"),
new XAttribute("Canvas.Top", 250),
new XAttribute("Width", "600"),
new XAttribute("Text", contact2.ToString())
);
// Add TextBlock control to the page
LayoutRoot.Children.Add(XamlReader.Load(textBlock1.ToString()) as UIElement);
// Add TextBlock control to the page
LayoutRoot.Children.Add(XamlReader.Load(textBlock2.ToString()) as UIElement);