Example #1
0
        /// <summary>
        /// Implements the template selection by finding the first selector among <see cref="Selectors"/> that returns a non null <see cref="DataTemplate"/>.
        /// </summary>
        /// <param name="item">The object.</param>
        /// <param name="container"></param>
        /// <returns>A <see cref="DataTemplate"/> for the <paramref name="item"/>.</returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            DataTemplate result = null;

            foreach (DataTemplateSelector s in Selectors)
            {
                if ((result = s.SelectTemplate(item, container)) != null)
                {
                    break;
                }
            }
            if (result == null && Fallback != null)
            {
                result = Fallback.SelectTemplate(item, container);
            }
            return(result);
        }