By Ian Lackey on
3/8/2010 4:38 PM
This is a very short and sweet post about dynamically switching the ItemTemplate property of a Silverlight ListBox at runtime. First we will start with a little background of what led to this article.
I am currently working on an application that contains a list of pediatric patients and their parents. I was recently given a requirement to display a parent name to one group of medical professional and the patient name to another group. However, either group should be able to toggle this display to allow searching on either the parent or patient.
Knowing that in Silverlight, simple is usually the correct answer, I figured this should in fact be simple. Thankfully, I was correct and after only a few minutes I had the following solution working.
If Me.SearchByParent.IsChecked Then
Me.PatientListBox.SetValue(ListBox.ItemTemplateProperty, _
Me.Resources("PatientParentListBoxTemplate"))
Else
Me.PatientListBox.SetValue(ListBox.ItemTemplateProperty,...
Read More »