using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using O2S.Components.PDFView4NET;
using O2S.Components.PDFView4NET.Forms;

namespace FormDesigner
{
    public partial class MainPage : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="MainPage"/> class.
        /// </summary>
        public MainPage()
        {
            InitializeComponent();
            DataContext = this;

            PdfControl.BeforeFieldAdd += new System.EventHandler<BeforeFieldAddEventArgs>(PdfControl_BeforeFieldAdd);
            PdfControl.FieldContextMenu += new System.EventHandler<FieldContextMenuEventArgs>(PdfControl_FieldContextMenu);
            PdfControl.PageClick += new System.EventHandler<PageClickEventArgs>(PdfControl_PageClick);
        }

        /// <summary>
        /// Handles the PageClick event of the PdfControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="O2S.Components.PDFView4NET.PageClickEventArgs"/> instance containing the event data.</param>
        private void PdfControl_PageClick(object sender, PageClickEventArgs e)
        {
            RemovePopupMenuFromUI(false);
        }

        private object _sender;
        private PDFField _selectedField;
        private PDFFieldWidget _selectedWidget;
        private Popup _contextMenuPopup = new Popup();

        /// <summary>
        /// Handles the FieldContextMenu event of the PdfControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="O2S.Components.PDFView4NET.FieldContextMenuEventArgs"/> instance containing the event data.</param>
        private void PdfControl_FieldContextMenu(object sender, FieldContextMenuEventArgs e)
        {
            if (PdfControl.WorkMode == UserInteractiveWorkMode.EditAnnotations)
            {
                _selectedField = e.Field;
                _selectedWidget = e.FieldWidget;

                Grid content = new Grid() { Background = new SolidColorBrush(Color.FromArgb(225, 225, 225, 225)) };
                content.RowDefinitions.Add(new RowDefinition());
                content.RowDefinitions.Add(new RowDefinition());

                Border border01 = new Border() { BorderBrush = new SolidColorBrush(Colors.Black), BorderThickness = new Thickness(1) };
                border01.MouseEnter += new System.Windows.Input.MouseEventHandler(HoverEffect_MouseEnter);
                border01.MouseLeave += new System.Windows.Input.MouseEventHandler(HoverEffect_MouseLeave);
                TextBlock textBlock01 = new TextBlock() { Text = "  Properties", Name = "Properties" };
                textBlock01.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(content_MouseLeftButtonDown);
                border01.Child = textBlock01;
                border01.SetValue(Grid.RowProperty, 0);

                Border border02 = new Border() { BorderBrush = new SolidColorBrush(Colors.Black), BorderThickness = new Thickness(1) };
                border02.MouseEnter += new System.Windows.Input.MouseEventHandler(HoverEffect_MouseEnter);
                border02.MouseLeave += new System.Windows.Input.MouseEventHandler(HoverEffect_MouseLeave);
                TextBlock textBlock02 = new TextBlock() { Text = "  Delete field  ", Name = "Delete" };
                textBlock02.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(content_MouseLeftButtonDown);
                border02.Child = textBlock02;
                border01.SetValue(Grid.RowProperty, 1);

                content.Children.Add(border01);
                content.Children.Add(border02);

                _contextMenuPopup.Child = content;

                // Considered mouse pointer size: 20x30. Added the mouse size to that the popup appears below it.
                _contextMenuPopup.HorizontalOffset = e.MousePosition.X + 20;
                _contextMenuPopup.VerticalOffset = e.MousePosition.Y + 30;
                _contextMenuPopup.IsOpen = true;

                _sender = sender;
            }
        }

        /// <summary>
        /// Handles the MouseLeave event of the control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseEventArgs"/> instance containing the event data.</param>
        private void HoverEffect_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            ((Border)sender).Background = new SolidColorBrush(Color.FromArgb(225, 225, 225, 225));
        }

        /// <summary>
        /// Handles the MouseEnter event of the control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseEventArgs"/> instance containing the event data.</param>
        private void HoverEffect_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            ((Border)sender).Background = new SolidColorBrush(Color.FromArgb(225, 225, 100, 100));
        }

        /// <summary>
        /// Handles the MouseLeftButtonDown event of the content control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        private void content_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (sender is TextBlock && _selectedField != null && _selectedWidget != null)
            {
                if (((TextBlock)sender).Name == "Delete")
                {
                    // Delete current field
                    RemovePopupMenuFromUI(true);
                }
                else
                {
                    // Show properties
                    RemovePopupMenuFromUI(false);
                    ShowPropertiesWindowForSelectedField();
                }

                e.Handled = true;
            }
        }

        /// <summary>
        /// Removes the popup menu from UI.
        /// </summary>
        /// <param name="deleteAnnotation">if set to <c>true</c> [delete annotation].</param>
        private void RemovePopupMenuFromUI(bool deleteAnnotation)
        {
            if (_contextMenuPopup.Child != null && _contextMenuPopup.Child is Grid && _selectedField != null && _selectedWidget != null)
            {
                ((Grid)_contextMenuPopup.Child).MouseLeftButtonDown -= new System.Windows.Input.MouseButtonEventHandler(content_MouseLeftButtonDown);
                ((Grid)_contextMenuPopup.Child).MouseEnter -= new System.Windows.Input.MouseEventHandler(HoverEffect_MouseEnter);
                ((Grid)_contextMenuPopup.Child).MouseLeave -= new System.Windows.Input.MouseEventHandler(HoverEffect_MouseLeave);

                _contextMenuPopup.Child = null;
                _contextMenuPopup.IsOpen = false;

                if (deleteAnnotation)
                {
                    DeleteCurrentField();
                }
            }
        }

        /// <summary>
        /// Deletes the current field.
        /// </summary>
        private void DeleteCurrentField()
        {
            if (_selectedField != null && _selectedWidget != null)
            {
                _selectedWidget.Page.Fields.Remove(_selectedField);
                _selectedField = null;
            }
        }

        /// <summary>
        /// Shows the properties window for selected field.
        /// </summary>
        private void ShowPropertiesWindowForSelectedField()
        {
            switch (_selectedField.Type)
            {
                case PDFFieldType.CheckBox:
                    CheckBoxPropertiesForm cbpf = new CheckBoxPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    cbpf.CheckBoxField = _selectedField as PDFCheckBoxField;
                    cbpf.CheckBoxWidget = (_selectedField as PDFCheckBoxField).Widgets[0] as PDFCheckBoxWidget;
                    cbpf.IsCancelable = false;
                    popupTool.Child = cbpf;
                    cbpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.DropDownList:
                    DropDownListPropertiesForm ddlpf = new DropDownListPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    ddlpf.DropDownListField = _selectedField as PDFDropDownListField;
                    ddlpf.DropDownListWidget = (_selectedField as PDFDropDownListField).Widgets[0] as PDFDropDownListWidget;
                    ddlpf.IsCancelable = false;
                    popupTool.Child = ddlpf;
                    ddlpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.ListBox:
                    ListBoxPropertiesForm lbpf = new ListBoxPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    lbpf.ListBoxField = _selectedField as PDFListBoxField;
                    lbpf.ListBoxWidget = (_selectedField as PDFListBoxField).Widgets[0] as PDFListBoxWidget;
                    lbpf.IsCancelable = false;
                    popupTool.Child = lbpf;
                    lbpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.PushButton:
                    PushButtonPropertiesForm pbpf = new PushButtonPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    pbpf.PushButtonField = _selectedField as PDFPushButtonField;
                    pbpf.PushButtonWidget = (_selectedField as PDFPushButtonField).Widgets[0] as PDFPushButtonWidget;
                    pbpf.IsCancelable = false;
                    popupTool.Child = pbpf;
                    pbpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.RadioButton:
                    RadioButtonPropertiesForm rbpf = new RadioButtonPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    rbpf.RadioButtonField = _selectedField as PDFRadioButtonListField;
                    rbpf.RadioButtonWidget = (_selectedField as PDFRadioButtonListField).Widgets[0] as PDFRadioButtonItem;
                    rbpf.IsCancelable = false;
                    popupTool.Child = rbpf;
                    rbpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.Signature:
                    SignaturePropertiesForm spf = new SignaturePropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    spf.SignatureField = _selectedField as PDFSignatureField;
                    spf.SignatureWidget = (_selectedField as PDFSignatureField).Widgets[0] as PDFSignatureWidget;
                    spf.IsCancelable = false;
                    popupTool.Child = spf;
                    spf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.TextBox:
                    TextBoxPropertiesForm tbpf = new TextBoxPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    tbpf.TextBoxField = _selectedField as PDFTextBoxField;
                    tbpf.TextBoxWidget = (_selectedField as PDFTextBoxField).Widgets[0] as PDFTextBoxWidget;
                    tbpf.IsCancelable = false;
                    popupTool.Child = tbpf;
                    tbpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
            }
        }

        private Popup popupTool = new Popup();

        /// <summary>
        /// Handles the BeforeFieldAdd event of the PdfControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="O2S.Components.PDFView4NET.BeforeFieldAddEventArgs"/> instance containing the event data.</param>
        private void PdfControl_BeforeFieldAdd(object sender, BeforeFieldAddEventArgs e)
        {
            switch (e.Field.Type)
            {
                case PDFFieldType.CheckBox:
                    CheckBoxPropertiesForm cbpf = new CheckBoxPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    cbpf.CheckBoxField = e.Field as PDFCheckBoxField;
                    cbpf.CheckBoxWidget = (e.Field as PDFCheckBoxField).Widgets[0] as PDFCheckBoxWidget;
                    _selectedField = cbpf.CheckBoxField;
                    _selectedWidget = cbpf.CheckBoxWidget;
                    cbpf.IsCancelable = true;
                    popupTool.Child = cbpf;
                    cbpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.DropDownList:
                    DropDownListPropertiesForm ddlpf = new DropDownListPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    ddlpf.DropDownListField = e.Field as PDFDropDownListField;
                    ddlpf.DropDownListWidget = (e.Field as PDFDropDownListField).Widgets[0] as PDFDropDownListWidget;
                    _selectedField = ddlpf.DropDownListField;
                    _selectedWidget = ddlpf.DropDownListWidget;
                    ddlpf.IsCancelable = true;
                    popupTool.Child = ddlpf;
                    ddlpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.ListBox:
                    ListBoxPropertiesForm lbpf = new ListBoxPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    lbpf.ListBoxField = e.Field as PDFListBoxField;
                    lbpf.ListBoxWidget = (e.Field as PDFListBoxField).Widgets[0] as PDFListBoxWidget;
                    _selectedField = lbpf.ListBoxField;
                    _selectedWidget = lbpf.ListBoxWidget;
                    lbpf.IsCancelable = true;
                    popupTool.Child = lbpf;
                    lbpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.PushButton:
                    PushButtonPropertiesForm pbpf = new PushButtonPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    pbpf.PushButtonField = e.Field as PDFPushButtonField;
                    pbpf.PushButtonWidget = (e.Field as PDFPushButtonField).Widgets[0] as PDFPushButtonWidget;
                    _selectedField = pbpf.PushButtonField;
                    _selectedWidget = pbpf.PushButtonWidget;
                    pbpf.IsCancelable = true;
                    popupTool.Child = pbpf;
                    pbpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.RadioButton:
                    RadioButtonPropertiesForm rbpf = new RadioButtonPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    rbpf.RadioButtonField = e.Field as PDFRadioButtonListField;
                    rbpf.RadioButtonWidget = (e.Field as PDFRadioButtonListField).Widgets[0] as PDFRadioButtonItem;
                    _selectedField = rbpf.RadioButtonField;
                    _selectedWidget = rbpf.RadioButtonWidget;
                    rbpf.IsCancelable = true;
                    popupTool.Child = rbpf;
                    rbpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.Signature:
                    SignaturePropertiesForm spf = new SignaturePropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    spf.SignatureField = e.Field as PDFSignatureField;
                    spf.SignatureWidget = (e.Field as PDFSignatureField).Widgets[0] as PDFSignatureWidget;
                    _selectedField = spf.SignatureField;
                    _selectedWidget = spf.SignatureWidget;
                    spf.IsCancelable = true;
                    popupTool.Child = spf;
                    spf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
                case PDFFieldType.TextBox:
                    TextBoxPropertiesForm tbpf = new TextBoxPropertiesForm() { Width = this.ActualWidth, Height = this.ActualHeight };
                    tbpf.TextBoxField = e.Field as PDFTextBoxField;
                    tbpf.TextBoxWidget = (e.Field as PDFTextBoxField).Widgets[0] as PDFTextBoxWidget;
                    _selectedField = tbpf.TextBoxField;
                    _selectedWidget = tbpf.TextBoxWidget;
                    tbpf.IsCancelable = true;
                    popupTool.Child = tbpf;
                    tbpf.Closed += popupTool_Closed;
                    popupTool.IsOpen = true;
                    break;
            }
        }

        /// <summary>
        /// Handles the Closed event of the popupTool control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void popupTool_Closed(object sender, System.EventArgs e)
        {
            if (sender is CheckBoxPropertiesForm)
            {
                ((CheckBoxPropertiesForm)sender).Closed -= popupTool_Closed;

                if (!((CheckBoxPropertiesForm)sender).AcceptChanges)
                {
                    DeleteCurrentField();
                }
            }
            else if (sender is DropDownListPropertiesForm)
            {
                ((DropDownListPropertiesForm)sender).Closed -= popupTool_Closed;

                if (!((DropDownListPropertiesForm)sender).AcceptChanges)
                {
                    DeleteCurrentField();
                }
            }
            else if (sender is ListBoxPropertiesForm)
            {
                ((ListBoxPropertiesForm)sender).Closed -= popupTool_Closed;

                if (!((ListBoxPropertiesForm)sender).AcceptChanges)
                {
                    DeleteCurrentField();
                }
            }
            else if (sender is PushButtonPropertiesForm)
            {
                ((PushButtonPropertiesForm)sender).Closed -= popupTool_Closed;

                if (!((PushButtonPropertiesForm)sender).AcceptChanges)
                {
                    DeleteCurrentField();
                }
            }
            else if (sender is RadioButtonPropertiesForm)
            {
                ((RadioButtonPropertiesForm)sender).Closed -= popupTool_Closed;

                if (!((RadioButtonPropertiesForm)sender).AcceptChanges)
                {
                    DeleteCurrentField();
                }
            }
            else if (sender is SignaturePropertiesForm)
            {
                ((SignaturePropertiesForm)sender).Closed -= popupTool_Closed;

                if (!((SignaturePropertiesForm)sender).AcceptChanges)
                {
                    DeleteCurrentField();
                }
            }
            else if (sender is TextBoxPropertiesForm)
            {
                ((TextBoxPropertiesForm)sender).Closed -= popupTool_Closed;

                if (!((TextBoxPropertiesForm)sender).AcceptChanges)
                {
                    DeleteCurrentField();
                }
            }

            popupTool.IsOpen = false;
        }

        private List<double> _zoomValues = new List<double>() { 25, 50, 75, 100, 125, 150, 200, 300, 400, 500, 600, 700, 800, 900, 1000 };

        /// <summary>
        /// Gets the zoom values.
        /// </summary>
        public List<double> ZoomValues
        {
            get
            {
                return _zoomValues;
            }
        }

        /// <summary>
        /// Handles the Click event of the OpenFile control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void OpenFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog browseFile = new OpenFileDialog();
            browseFile.Multiselect = false;
            browseFile.Filter = "PDF Files (*.pdf)|*.pdf";

            bool? result = browseFile.ShowDialog();

            if (result is bool && (bool)result)
            {
                PdfControl.Document = new PDFDocument();
                PdfControl.Document.Load(browseFile.File.OpenRead());
            }
        }

        /// <summary>
        /// Handles the Click event of the SaveFile control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void SaveFile_Click(object sender, RoutedEventArgs e)
        {
            if (PdfControl.Document != null && PdfControl.Document.PageCount > 0)
            {
                SaveFileDialog saveDialog = new SaveFileDialog();
                saveDialog.Filter = "PDF Files (*.pdf)|*.pdf";
                bool? result = saveDialog.ShowDialog();

                if (result is bool && (bool)result)
                {
                    System.IO.Stream stream = saveDialog.OpenFile();
                    PdfControl.Document.Save(stream);
                    stream.Close();
                }
            }
            else
            {
                MessageBox.Show("Nothing to save.", "Message", MessageBoxButton.OK);
            }
        }

        private Button _selectedButton;

        /// <summary>
        /// Gets or sets the selected button.
        /// </summary>
        /// <value>
        /// The selected button.
        /// </value>
        private Button SelectedButton
        {
            get
            {
                return _selectedButton;
            }
            set
            {
                if (_selectedButton != null)
                {
                    // Unselect previous button
                    _selectedButton.BorderBrush = new SolidColorBrush(Colors.Transparent);
                }

                _selectedButton = value;

                if (_selectedButton != null)
                {
                    // Select button
                    _selectedButton.BorderBrush = new SolidColorBrush(Colors.Blue);
                }
            }
        }

        /// <summary>
        /// Sets the work mode.
        /// </summary>
        /// <param name="pressedButton">The pressed button.</param>
        /// <param name="workMode">The work mode.</param>
        private void SetWorkMode(Button pressedButton, UserInteractiveWorkMode workMode)
        {
            PdfControl.WorkMode = workMode;
            SelectedButton = pressedButton as Button;
        }

        /// <summary>
        /// Handles the Click event of the PanAndScanClick control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void PanAndScan_Click(object sender, RoutedEventArgs e)
        {
            SetWorkMode(sender as Button, UserInteractiveWorkMode.PanAndScan);
        }

        /// <summary>
        /// Handles the Click event of the EditAnnotations control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void EditAnnotations_Click(object sender, RoutedEventArgs e)
        {
            SetWorkMode(sender as Button, UserInteractiveWorkMode.EditAnnotations);
        }

        /// <summary>
        /// Handles the Click event of the TextBoxField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void TextBoxField_Click(object sender, RoutedEventArgs e)
        {
            SetWorkMode(sender as Button, UserInteractiveWorkMode.AddTextBoxField);
        }

        /// <summary>
        /// Handles the Click event of the CheckBoxField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void CheckBoxField_Click(object sender, RoutedEventArgs e)
        {
            SetWorkMode(sender as Button, UserInteractiveWorkMode.AddCheckBoxField);
        }

        /// <summary>
        /// Handles the Click event of the RadioButtonField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void RadioButtonField_Click(object sender, RoutedEventArgs e)
        {
            SetWorkMode(sender as Button, UserInteractiveWorkMode.AddRadioButtonField);
        }

        /// <summary>
        /// Handles the Click event of the ListBoxField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void ListBoxField_Click(object sender, RoutedEventArgs e)
        {
            SetWorkMode(sender as Button, UserInteractiveWorkMode.AddListBoxField);
        }

        /// <summary>
        /// Handles the Click event of the ComboBoxField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void ComboBoxField_Click(object sender, RoutedEventArgs e)
        {
            SetWorkMode(sender as Button, UserInteractiveWorkMode.AddDropDownListField);
        }

        /// <summary>
        /// Handles the Click event of the ButtonField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void ButtonField_Click(object sender, RoutedEventArgs e)
        {
            SetWorkMode(sender as Button, UserInteractiveWorkMode.AddPushButtonField);
        }

        /// <summary>
        /// Handles the Click event of the DigitalSignatureField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void DigitalSignatureField_Click(object sender, RoutedEventArgs e)
        {
            SetWorkMode(sender as Button, UserInteractiveWorkMode.AddSignatureField);
        }
    }
}
