New to Telerik UI for WPF? Download free 30-day trial

XML Binding

The current version of Silverlight does not support direct XML binding but LINQ to XML can be used to retrieve the necessary data. The following example loads a collection of dates from an xml file and assigns them as the selected dates of a calendar.

The DataSource.xml file has the following content:


The following code snippet loads the file and extracts the Date nodes out of it, then assigns the respective dates as selection:

// Make sure that more than one date can be selected: 
calendar.SelectionMode = SelectionMode.Extended; 
// Load the xml document and get the culture with wich the dates were serialized: 
XDocument xmlSource = XDocument.Load("DataSource.xml"); 
CultureInfo usCulture = new CultureInfo("En-US"); 
// Add Get all the dates in the xml document and add them as selected dates: 
foreach (var dateNode in xmlSource.Descendants("Date")) 
    calendar.SelectedDates.Add(DateTime.Parse(dateNode.Value, usCulture.DateTimeFormat)); 
// Set the display date to the forst selected date, so that the selection is visible. 
calendar.DisplayDate = (DateTime)calendar.SelectedDates[0]; 
In this article