Click here to Skip to main content
15,885,985 members
Articles / Desktop Programming / XAML

Extending GridView with Drag and Drop for Grouping and Variable Sized Items

,
Rate me:
Please Sign up or sign in to vote.
4.98/5 (23 votes)
9 Oct 2015CPOL11 min read 134.6K   8K   69  
This article describes the implementation of an extended GridView control that enables drag and drop with grouping and variable sized items.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;

namespace GridViewSamples.DataModel
{
    public class Item
    {
        static List<Windows.UI.Color> colors = typeof(Windows.UI.Colors)
          .GetRuntimeProperties()
          .Select((x) => (Windows.UI.Color)x.GetValue(null)).ToList<Windows.UI.Color>();

        public int Id { get; set; }
        public int GroupId { get; set; }
        public Windows.UI.Color GroupColor
        {
            get
            {
                int index = GroupId;
                while (index > colors.Count - 1)
                {
                    index -= colors.Count;
                }
                return colors[index];
            }
        }
    }

    public class Group
    {
        // static integer which should be used as group Id for the new group
        private static int newGroupId = 1;

        private int _id;

        public static Group GetNewGroup()
        {
            Group gr = new Group();
            gr.Id = newGroupId;
            return gr;
        }

        private Group()
        {
            Items = new ObservableCollection<Item>();
        }

        public int Id
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
                if (newGroupId <= _id)
                {
                    // update newGroupId so that Id is unique
                    newGroupId = _id + 1;
                }
            }
        }
        public ObservableCollection<Item> Items { get; set; }
    }
}

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
Program Manager GrapeCity
Russian Federation Russian Federation
I'm the GrapeCity program manager for ComponentOne Studio.
If you need more info, learn about our products here: http://www.grapecity.com/

Written By
Product Manager GrapeCity
United States United States
I am the ComponentOne product manager at GrapeCity. I love .NET but especially the XAML platforms. You'll find me blogging about these awesome technologies and at various code camps, techfests and tradeshows.

Comments and Discussions