2
using System.Collections.Generic;
3
using System.Windows.Controls;
4
using System.Windows.Markup;
6
namespace System.Windows.Controls
8
internal sealed class ResourceHelper
10
static Dictionary<string, string> _cache = new Dictionary<string, string>();
12
private ResourceHelper()
16
static public ControlTemplate GetControlTemplate<T>()
18
return GetControlTemplate(typeof(T));
21
static public ControlTemplate GetControlTemplate(Type type)
23
return GetControlTemplate(type, type.FullName);
26
static public ControlTemplate GetControlTemplate(Type type, string resourceName)
28
string xaml = ResourceHelper.GetTemplateXaml(type, resourceName);
30
if (String.IsNullOrEmpty(xaml))
32
throw new Exception(type.Name + " xaml could not be loaded");
40
ControlTemplate result = (ControlTemplate)XamlReader.Load(xaml);
53
static public string GetTemplateXaml(Type type, string resourceName)
57
if (!_cache.TryGetValue(resourceName, out template))
59
System.IO.Stream s = type.Assembly.GetManifestResourceStream(resourceName + ".xaml");
62
template = new System.IO.StreamReader(s).ReadToEnd();
63
_cache[resourceName] = template;