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

using C1.Silverlight.Theming;
using C1.Silverlight.Theming.ExpressionDark;
using System.Windows.Media;
using System.Windows;
using System.Windows.Controls.Primitives;
using MyCustomTheme;

namespace CustomThemes
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            C1.Silverlight.C1Window.AddDefaultPopupToVisualTree(LayoutRoot);

            // handle C1Theme loading errors
            C1Theme.LoadingError += new System.EventHandler<C1ThemeLoadingErrorEventArgs>(C1Theme_LoadingError);
        }

        void C1Theme_LoadingError(object sender, C1ThemeLoadingErrorEventArgs e)
        {
            errors.ItemsSource = e.Errors;
        }


        private void btnED_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ApplyTheme((ToggleButton)sender, new C1ThemeExpressionDark());
        }

        private void btnExtendedED_Click(object sender, RoutedEventArgs e)
        {
            ApplyTheme((ToggleButton)sender, new MyCustomExpressionDark());
        }

        private void btnCusomTheme_Click(object sender, RoutedEventArgs e)
        {
            ApplyTheme((ToggleButton)sender, new MyCustomTheme.MyCustomTheme());
        }


        ToggleButton _lastSelected;
        private void ApplyTheme(ToggleButton button, C1Theme theme)
        {
            if (_lastSelected != null)
            {
                _lastSelected.IsChecked = false;
            }
            _lastSelected = button;

            theme.Apply(LayoutRoot);
            LayoutRoot.Background = (Brush)C1Theme.GetCurrentThemeResources(theme)["MouseOverGradientBrush"];
        }
    }
}

