Mega Code Archive
Binding Using a DataTemplate
//File: Page.xaml.cs
using System.Collections.Generic;
using System.Windows.Controls;
namespace SilverlightApplication3
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
List EmployeeList = new List();
EmployeeList.Add(new Employee
{
FirstName = "A",
LastName = "B",
PhoneNum = 2,
Address = new Address { Street = "2 Street", City = "New York", State = "NY", ZipCode = 10006 }
});
EmployeeList.Add(new Employee{
FirstName = "C",
LastName = "D",
PhoneNum = 7,
Address = new Address { Street = "1 Road", City = "New York", State = "NY", ZipCode = 10016 }
});
cntctrlEmployee.Content = EmployeeList[0];
itmctrlEmployees.ItemsSource = EmployeeList;
}
}
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public long PhoneNum { get; set; }
public string ImageUri
{
get
{
return "/" + FirstName + ".png";
}
}
public Address Address { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
public int ZipCode { get; set; }
}
}