using System;
using System.Collections.Generic;
using Windows.UI.Text;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace ControlExplorer.Controls.RichTextBox
{
    public partial class RichTextBoxFormatting : UserControl, IExposeApplicationBarItems
    {
        AppBarButton btnFormat = new AppBarButton { Icon = new BitmapIcon { UriSource = new Uri("ms-appx:///Resources/AppBar/brush.png") } };

        public RichTextBoxFormatting()
        {
            InitializeComponent();

            btnFormat.Label = "format";
            btnFormat.Click += btnFormat_Click;

            // set FormatPopup properties
            FormatPopup.RichTextBox = rtb;
            FormatPopup.Popup = Popup;
            Popup.Closed += Popup_Closed;
        }

        void Popup_Closed(object sender, object e)
        {
            btnFormat.Visibility = Visibility.Visible;
        }

        void btnFormat_Click(object sender, RoutedEventArgs e)
        {
            // show format popup
            Popup.IsOpen = true;
            btnFormat.Visibility = Visibility.Collapsed;
        }

        public IEnumerable<ICommandBarElement> ApplicationBarItems
        {
            get
            {
                yield return btnFormat;
            }
        }
    }
}
