Skip to content

Instantly share code, notes, and snippets.

@dbeattie71
Created February 9, 2012 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbeattie71/1781678 to your computer and use it in GitHub Desktop.
Save dbeattie71/1781678 to your computer and use it in GitHub Desktop.
ApplyItemTemplate
public static void ApplyItemTemplate(ItemsControl itemsControl, PropertyInfo property) {
if (!string.IsNullOrEmpty(itemsControl.DisplayMemberPath)
|| HasBinding(itemsControl, ItemsControl.DisplayMemberPathProperty)
|| itemsControl.ItemTemplate != null
|| !property.PropertyType.IsGenericType) {
return;
}
#if !WP71
var itemType = property.PropertyType.GetGenericArguments().First();
if (itemType.IsValueType || typeof(string).IsAssignableFrom(itemType)) {
return;
}
#endif
#if NET
if (itemsControl.ItemTemplateSelector == null){
itemsControl.ItemTemplate = DefaultItemTemplate;
Log.Info("ItemTemplate applied to {0}.", itemsControl.Name);
}
#else
itemsControl.ItemTemplate = DefaultItemTemplate;
Log.Info("ItemTemplate applied to {0}.", itemsControl.Name);
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment