Click here to Skip to main content
15,892,674 members
Articles / Web Development / HTML

My Personal Commander Variant

Rate me:
Please Sign up or sign in to vote.
4.66/5 (13 votes)
5 Oct 2016CPOL14 min read 44.6K   1.2K   47  
A C#/WPF application for displaying folders on a grid and performing combined functions on them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Markup;

namespace Lobster.MVVM
{
    [ContentProperty("Templates")]
    public class NameBasedTemplateSelector : DataTemplateSelector
    {
        public NameBasedTemplateSelector()
        {
            templates = new List<NamedTemplate>();
        }

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var i = item as ITemplateNameProvider;
            if (i == null) return null;

            foreach (var t in Templates)
            {
                if (t.Name == i.TemplateName) return t.DataTemplate;
            }
            return null;
        }

        private List<NamedTemplate> templates;

        public List<NamedTemplate> Templates { get { return templates; } }
    }

    /// <summary>
    /// Provides a pair of TemplateName and DataTemplate. It is created 
    /// directly in XAML.
    /// </summary>
    [ContentProperty("DataTemplate")]
    public class NamedTemplate
    {
        public string Name { get; set; }
        public DataTemplate DataTemplate { get; set; }
    }

    /// <summary>
    /// A viewmodel must provide this interface in order to let a
    /// NameBasedTemplateSelector know its TemplateName.
    /// </summary>
    public interface ITemplateNameProvider
    {
        string TemplateName { get; }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions