Created
September 21, 2012 05:32
-
-
Save nanofi/3759888 to your computer and use it in GitHub Desktop.
DataTemplateSelector condition with item class name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Windows.UI.Xaml; | |
using Windows.UI.Xaml.Controls; | |
using Windows.UI.Xaml.Markup; | |
namespace Nanofi.Common{ | |
[ContentProperty(Name = "Resources")] | |
public class ClassNameDataTemplateSelector : DataTemplateSelector | |
{ | |
public ResourceDictionary Resources { get; set; } | |
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) | |
{ | |
if (Resources == null) return null; | |
string target = string.Format("{0}DataTemplate", item.GetType().Name); | |
return Resources.ContainsKey(target) ? Resources[target] as DataTemplate : null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment