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

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

      Loaded += (se, ev) =>
      {
        foreach (var key in Resources.Keys)
        {
          var cmd = Resources[key] as C1ToolbarCommand;
          if (cmd != null)
          {
            CommandManager.RegisterClassCommandBinding(GetType(), new CommandBinding(
              cmd, (s, e) => Execute(cmd.LabelTitle), (s, e) => e.CanExecute = true));
          }
        }
        CommandManager.InvalidateRequerySuggested();
      };

      toolbar.HelpClick += (s, e) => MessageBox.Show("HelpClick");
    }

    void Execute(string text)
    {
      tb.Text += text + "\n";
      tb.SelectionStart = tb.Text.Length;
    }

    private void C1ToolbarGroup_DialogLauncherClick(object sender, EventArgs e)
    {
      var tbgroup = (C1ToolbarGroup)sender;
      MessageBox.Show(tbgroup.Header.ToString() + " Dialog");
    }
  }
}
