using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using GridViewColumnSortState;
using Telerik.Windows.Controls;

namespace ImageColumn
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();

            var senderColumn = new GridViewDataColumn() { UniqueName = "Sender" };
            this.RadGridView1.Columns.Add(senderColumn);

            var imageColumn = new ImageColumn() { Width = new GridLength(280) } ;
            this.RadGridView1.Columns.Add(imageColumn);

            this.RadGridView1.ItemsSource = GetMessages();
        }

        private IList<Message> GetMessages()
        {
            var testImage = "Images/VoteForTelerik.jpg";
            return new Message[] { 
			                     	new Message { Sender = "tom@hanna-barbera.com", Subject = "Cats are cool", Size = 100, Image = testImage },
			                     	new Message { Sender = "jerry@hanna-barbera.com", Subject = "Mice are cool", Size = 100, Image = testImage },
			                     	new Message { Sender = "spike@hanna-barbera.com", Subject = "Dogs are cool", Size = 100, Image = testImage }
			                     };
        }

    }

    public class ImageColumn : GridViewDataColumn
    {
        public override FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
        {
            var cellImage = new Image() { Width = 272, Height = 125 };
            var imageUri = ((Message) dataItem).Image;
            cellImage.Source = new BitmapImage(new Uri(imageUri, UriKind.Relative));
            return cellImage;
        }
    }
}
