using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace MainTestApplication
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            SetSampleText(_samplesTab.SelectedItem as TabItem);
        }

        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                SetSampleText(e.AddedItems[0] as TabItem);
            }
        }

        private void SetSampleText(TabItem tab)
        {
            if (tab != null)
            {
                FrameworkElement sample = tab.Content as FrameworkElement;
                if ((sample != null) && (_sampleText != null))
                {
                    _sampleText.Text = sample.Tag as string;
                }
            }
        }
    }

    // converter used to group countries by their first initial
    class CountryInitialConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ((string)value)[0].ToString().ToUpper();
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
