/// <summary>
 ///  Clears the cache when the set of templates change
 /// </summary>
 /// <param name="bo"></param>
 /// <param name="oldval"></param>
 /// <param name="newval"></param>
 public static void TemplatesChanged(BindableObject bo, DataTemplateCollection oldval, DataTemplateCollection newval)
 {
     var ts = bo as TemplateSelector;
     if (ts == null) return;
     if (oldval != null) oldval.CollectionChanged -= ts.TemplateSetChanged;
     newval.CollectionChanged += ts.TemplateSetChanged;
     ts.Cache = null;
 }
Beispiel #2
0
        /// <summary>
        ///  Clears the cache when the set of templates change
        /// </summary>
        /// <param name="bo"></param>
        /// <param name="oldval"></param>
        /// <param name="newval"></param>
        public static void TemplatesChanged(BindableObject bo, DataTemplateCollection oldval, DataTemplateCollection newval)
        {
            var ts = bo as TemplateSelector;

            if (ts == null)
            {
                return;
            }
            if (oldval != null)
            {
                oldval.CollectionChanged -= ts.TemplateSetChanged;
            }
            newval.CollectionChanged += ts.TemplateSetChanged;
            ts.Cache = null;
        }
        static Dictionary <Type, Windows.UI.Xaml.DataTemplate> MakeTypeToTemplateMap(DataTemplateCollection templateCollection)
        {
            var map = new Dictionary <Type, Windows.UI.Xaml.DataTemplate>();

            foreach (var template in templateCollection)
            {
                var targetType = DataTemplate.GetTargetType(template);
                if (targetType == null)
                {
                    throw new Exception("TargetTypeProperty must be set your Type. (restrict only TypeBasedTemplateSelector insided DateTemplate)");
                }

                if (map.ContainsKey(targetType))
                {
                    throw new Exception("Duplicate TargetTypeProperty present Type's in DataTemplate. Ensure indivisual Type to set DataTemplate with TargetType.");
                }

                map.Add(targetType, template);
            }

            return(map);
        }
Beispiel #4
0
 /// <summary>
 /// Initialize the TemplateCollections so that each
 /// instance gets it's own collection
 /// </summary>
 public TemplateSelector()
 {
     Templates = new DataTemplateCollection();
 }
        /// <summary>
        /// Creates an instance of a <see cref="XamlTemplateSelector"/> object.
        /// </summary>

        public XamlTemplateSelector()
        {
            _templates = new DataTemplateCollection();
        }
 /// <summary>
 /// Initialize the TemplateCollections so that each 
 /// instance gets it's own collection
 /// </summary>
 public TemplateSelector()
 {
     Templates = new DataTemplateCollection();
 }