コード例 #1
0
 public static IEnumerable <DictionaryEntry> CustomDataTemplates(this Type type, ResourceDictionary res)
 {
     foreach (var entry in res.Cast <DictionaryEntry>())
     {
         var(key, value) = entry;
         if (value is DataTemplate {
             DataType: Type datatype
         })
コード例 #2
0
        /// <summary>
        ///根据资源字典路径和资源的key,找到资源
        ///  //source实例
        //_resourceDictionary.Source = new Uri(@"pack://application:,,,/MEFA.Common.Audit;component/Communication/Controls/TreeViewItemToggleButtonStyle.xaml");
        /// </summary>
        /// <param name="sourcePath"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static T FindSourceByKey <T>(string sourcePath, string key) where T : class
        {
            ResourceDictionary _resourceDictionary = new ResourceDictionary();

            _resourceDictionary.Source = new Uri(sourcePath);
            var list = _resourceDictionary.Cast <DictionaryEntry>().ToList();

            if (list == null || list.Count < 1)
            {
                return(null);
            }
            return((T)list.Where(o => o.Key.ToString() == key).First().Value);
        }
コード例 #3
0
        public static IEnumerable <ResourceEntry <T> > GetResourcesRecursively <T>(ResourceDictionary resourceDictionary)
        {
            if (resourceDictionary == null)
            {
                return(Enumerable.Empty <ResourceEntry <T> >());
            }

            var resourceEntries = resourceDictionary.Cast <DictionaryEntry>().Where(d => d.Value is T)
                                  .Select(r => new ResourceEntry <T> {
                Key = r.Key, Value = (T)r.Value, Owner = resourceDictionary
            });

            foreach (var mergedDictionary in resourceDictionary.MergedDictionaries)
            {
                resourceEntries = resourceEntries.Union(GetResourcesRecursively <T>(mergedDictionary));
            }

            return(resourceEntries);
        }
コード例 #4
0
 public ResourceDictionaryKeyValue(string key, ResourceDictionary resourceDictionary)
 {
     Key = key;
     ResourceDictionary = resourceDictionary;
     lazy = new(() => new MasterDetailGrid(resourceDictionary.Cast <DictionaryEntry>().Select(a => new DataTemplateKeyValue(a)).ToArray()));
 }