namespace WPFWordControl
{
    #region Using
    using System;
    using System.Windows;
    using System.Windows.Controls;

    using WPFWordControl.WindowsForms;
    #endregion

    public partial class Word : UserControl
    {
        #region Свойства
        private WordWindowsForms control;
        #endregion

        #region Конструктор
        public Word()
        {
            InitializeComponent();

            this.Loaded += UserControl_Loaded;
        }
        #endregion

        #region Общие методы
        public void Print()
        {
            this.control.PrintWordDocument();
        }
        #endregion

        #region Dependency Property
        /// <summary>
        /// Путь к файлу
        /// </summary>
        public string File
        {
            get { return (string)this.GetValue(FileProperty); }
            set { this.SetValue(FileProperty, value); }
        }

        public static readonly DependencyProperty FileProperty = DependencyProperty.Register("File", typeof(string), typeof(Word), new PropertyMetadata(null, OnFilePropertyChanged));

        public static void OnFilePropertyChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            Word ech = sender as Word;

            if (ech == null || ech.control == null)
                return;

            if (string.IsNullOrWhiteSpace((string)e.NewValue))
                ech.control.CloseWordDocument();
            else
                ech.control.OpenWordDocument((string)e.NewValue);
        }
        #endregion

        #region События
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.control = new WordWindowsForms();

            this.wordHost.Child = this.control;
        }
        #endregion
    }
}
