using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
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 ClearStyleTabControl
	{
		public ClearStyleTabControl()
		{
			InitializeComponent();
		}

		private bool _closing = false;
		private void tabs_TabClosing(object sender, CancelSourceEventArgs e)
		{
			if (!_closing)
			{
				_closing = true;
				C1TabItem tabItem = (C1TabItem)e.Source;
				e.Cancel = true;
				C1.Silverlight.C1MessageBox.Show("Do you really want to close this tab?", "Close Tabs?", C1MessageBoxButton.YesNo, C1MessageBoxIcon.Question,
					(result) =>
					{
						if (result == MessageBoxResult.Yes)
						{
							Items.Remove(tabItem);
						}
						_closing = false;
					});
			}
		}

		private void C1TabItem_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			// create new item
			var item = new C1TabItem()
			{
				Header = string.Format("Item {0}", this.Items.Count)
			};

			this.Items.Insert(this.Items.Count - 1, item);
			this.SelectedItem = item;
		}
	}
}
