Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports C1.Silverlight.Schedule
Imports C1.C1Schedule
Imports C1.Silverlight.Theming
Imports C1.Silverlight

Namespace Theming
	Partial Public Class MainPage
		Inherits UserControl
		Private _themes As New List(Of C1Theme)()

		Public Sub New()
			_themes.Add(New C1.Silverlight.Theming.Cosmopolitan.C1ThemeCosmopolitan())
            _themes.Add(New C1.Silverlight.Theming.CosmopolitanDark.C1ThemeCosmopolitanDark())
            _themes.Add(New C1.Silverlight.Theming.WhistlerBlue.C1ThemeWhistlerBlue())
			_themes.Add(New C1.Silverlight.Theming.RainierOrange.C1ThemeRainierOrange())
			_themes.Add(New C1.Silverlight.Theming.BureauBlack.C1ThemeBureauBlack())
			_themes.Add(New C1.Silverlight.Theming.ExpressionDark.C1ThemeExpressionDark())
			_themes.Add(New C1.Silverlight.Theming.ExpressionLight.C1ThemeExpressionLight())
			_themes.Add(New C1.Silverlight.Theming.ShinyBlue.C1ThemeShinyBlue())
            _themes.Add(New C1.Silverlight.Theming.Office2010.C1ThemeOffice2010Blue())
			_themes.Add(New C1.Silverlight.Theming.Office2010.C1ThemeOffice2010Black())
			_themes.Add(New C1.Silverlight.Theming.Office2010.C1ThemeOffice2010Silver())
            _themes.Add(New C1.Silverlight.Theming.Office2007.C1ThemeOffice2007Blue())
			_themes.Add(New C1.Silverlight.Theming.Office2007.C1ThemeOffice2007Black())
			_themes.Add(New C1.Silverlight.Theming.Office2007.C1ThemeOffice2007Silver())
            _themes.Add(New C1.Silverlight.Theming.Office2013.C1ThemeOffice2013White())
            _themes.Add(New C1.Silverlight.Theming.Office2013.C1ThemeOffice2013LightGray())
            _themes.Add(New C1.Silverlight.Theming.Office2013.C1ThemeOffice2013DarkGray())

			InitializeComponent()

			' the next line is required in order to apply themes to all C1Window instances 
			C1Window.AddDefaultPopupToVisualTree(LayoutRoot)
			Dim themes As New List(Of String)()
			themes.Add("Cosmopolitan")
            themes.Add("Cosmopolitan Dark")
            themes.Add("Whistler Blue")
			themes.Add("Rainier Orange")
			themes.Add("Bureau Black")
			themes.Add("Expression Dark")
			themes.Add("Expression Light")
			themes.Add("Shiny Blue")
            themes.Add("Office 2010 Blue")
			themes.Add("Office 2010 Black")
			themes.Add("Office 2010 Silver")
            themes.Add("Office 2007 Blue")
			themes.Add("Office 2007 Black")
			themes.Add("Office 2007 Silver")
            themes.Add("Office 2013 White")
            themes.Add("Office 2013 Light Gray")
            themes.Add("Office 2013 Dark Gray")

			ThemesCombo.ItemsSource = themes
			ThemesCombo.SelectedIndex = 0

			Dim theme As C1Theme = _themes(0)
			theme.Apply(Me)
			sched1.Theme = C1Theme.GetCurrentThemeResources(theme)

		End Sub

		Private Sub UserControl_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
			' update toolbar buttons state
			sched1_StyleChanged(Nothing, Nothing)
			AddHandler ThemesCombo.SelectionChanged, AddressOf ThemesCombo_SelectionChanged
		End Sub

		Private Sub btnToday_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
			sched1.VisibleDates.BeginUpdate()
			sched1.VisibleDates.Clear()
			sched1.VisibleDates.Add(Date.Today)
			sched1.VisibleDates.EndUpdate()
		End Sub

		Private Sub sched1_StyleChanged(ByVal sender As Object, ByVal e As RoutedEventArgs)
			' update toolbar buttons state according to the current C1Scheduler view
            If sched1.Style Is sched1.WorkingWeekStyle Then
                btnWorkWeek.IsChecked = True
            ElseIf sched1.Style Is sched1.WeekStyle Then
                btnWeek.IsChecked = True
            ElseIf sched1.Style Is sched1.MonthStyle Then
                btnMonth.IsChecked = True
            ElseIf sched1.Style Is sched1.TimeLineStyle Then
                btnTimeLine.IsChecked = True
            Else
                btnDay.IsChecked = True
            End If
		End Sub

		Private Sub ThemesCombo_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
			Dispatcher.BeginInvoke(Sub() ApplyTheme())
		End Sub

		Private Sub ApplyTheme()
			Dim theme As C1Theme = _themes(ThemesCombo.SelectedIndex)
			theme.Apply(Me)
			sched1.Theme = C1Theme.GetCurrentThemeResources(theme)
		End Sub

		Private Sub Grouping_Unchecked(sender As System.Object, e As System.Windows.RoutedEventArgs)
			sched1.GroupBy = ""
		End Sub

		Private Sub Grouping_Checked(sender As System.Object, e As System.Windows.RoutedEventArgs)
			sched1.GroupBy = "Category"
		End Sub
	End Class
End Namespace
