using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Telerik.Windows.Controls;
using System.Collections;
using System.Collections.ObjectModel;

namespace ForeignKeyForSilverlight
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            this.radGridViewEditorSettings.ItemsSource = this.CreatePersonsList();
            this.Loaded += this.Page_Loaded;
        }

        private ObservableCollection<Person> CreatePersonsList()
        {
            ObservableCollection<Person> persons = new ObservableCollection<Person>();
            persons.Add(new Person
            {
                PersonType = new PersonType
                {
                    PersonTypeID = 1,
                    JobTitle = "General Staff"
                },
                EmployeeName = "Johann"
            });
            persons.Add(new Person
            {
                PersonType = new PersonType
                {
                    PersonTypeID = 2,
                    JobTitle = "Manager"
                },
                EmployeeName = "Maria"
            });
            return persons;
        }

        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            CustomComboBoxEditorSettings editorSettings = new CustomComboBoxEditorSettings();
            editorSettings.ItemsSource = this.CreatePersonTypeList();
            editorSettings.DisplayMemberPath = "JobTitle";
            ((GridViewDataColumn) this.radGridViewEditorSettings.Columns[1]).EditorSettings = editorSettings;
        }

        private IEnumerable CreatePersonTypeList()
        {
            List<PersonType> result = new List<PersonType>();
            result.Add(new PersonType
            {
                PersonTypeID = 1,
                JobTitle = "General Staff"
            });
            result.Add(new PersonType
            {
                PersonTypeID = 2,
                JobTitle = "Manager"
            });
            result.Add(new PersonType
            {
                PersonTypeID = 3,
                JobTitle = "Supervisor"
            });
            return result;
        }
    }
}
