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.Shapes;
using C1.Silverlight;

namespace C1_Demo
{
    public partial class DemoComboBoxCustom : UserControl
    {
        public DemoComboBoxCustom()
        {
            InitializeComponent();
            
            // Countries
            comboCountries.ItemsSource = Country.List; 
            comboCountries.SelectedIndexChanged += new EventHandler<PropertyChangedEventArgs<int>>(comboCountries_SelectedIndexChanged);

            // Font Families
            comboFontFamilies.ItemConverter = new FontFamilyStringConverter();
            comboFontFamilies.Items.Add(new FontFamily("Portable User Interface"));
            comboFontFamilies.Items.Add(new FontFamily("Arial"));
            comboFontFamilies.Items.Add(new FontFamily("Arial Black"));
            comboFontFamilies.Items.Add(new FontFamily("Comic Sans MS"));
            comboFontFamilies.Items.Add(new FontFamily("Courier New"));
            comboFontFamilies.Items.Add(new FontFamily("Lucida Grande"));
            comboFontFamilies.Items.Add(new FontFamily("Lucida Sans Unicode"));
            comboFontFamilies.Items.Add(new FontFamily("Times New Roman"));
            comboFontFamilies.Items.Add(new FontFamily("Trebuchet MS"));
            comboFontFamilies.Items.Add(new FontFamily("Verdana"));

            // Customer
            comboCustomers.ItemsSource = Person.Generate(20);
        }

        void comboCountries_SelectedIndexChanged(object sender, PropertyChangedEventArgs<int> e)
        {
            if (SelectedItemChanged != null)
                SelectedItemChanged(comboCountries, e);
        }

        public event EventHandler SelectedItemChanged;

        #region events

        private string comboCountries_ConvertItemToString(object arg)
        {
            if (arg == null) return string.Empty;

            return ((Country)arg).Name;
        }
        private object comboCountries2_ConvertStringToItem(string arg)
        {
            return new Country("no-image") { Name = arg };
        }

        #endregion
    }
}
