private void MenuItem_Click_17(object sender, RoutedEventArgs e)
        {
            var od = new OpenFileDialog();
            od.ShowDialog();

            if (string.IsNullOrEmpty(od.FileName))
            {
                return;
            }

            Preambula.Clear();
            UpdateRemarks();
            Questions.Items.Clear();
            XElement root = null;

            try
            {
                root = XElement.Load(od.FileName);
            }
            catch (Exception ex)
            {
                Hider.Visibility = Visibility.Visible;
                OkMessage yn = new OkMessage("Некорректный файл", "Файл, который вы пытаетесь загрузить, загружен некорректно, ошибка \"" + ex.Message + "\"");
                yn.ShowDialog();
                Hider.Visibility = Visibility.Hidden;
                return;
            }

            CurrentFileName = od.FileName;
            CurrentDirectory = od.FileName;
            int ind = CurrentDirectory.Length - 1;
            while (CurrentDirectory[ind] != '\\')
            {
                ind--;
            }
            CurrentDirectory = CurrentDirectory.Substring(0, ind + 1);

            LoadQuestions(root);
            LoadRemarks(root.Element("Preambula"));

            if (Questions.Items.Count == 0)
            {
                MiddleEditor.IsEnabled = false;
            }
            FileTitle.Text = CurrentFileName;
        }
        private void MenuItem_Click_4(object sender, RoutedEventArgs e)
        {
            try
            {
                var tempFileName = Directory.GetCurrentDirectory();
                var test = new XElement("Test");
                test.SetAttributeValue("TestName", tempFileName + "test.xml");

                var question = new XElement("Question");
                int ind = 0;
                foreach (Question item in Questions.Items)
                {
                    question.Add(QuestionToElement(item, ind));
                    ind++;
                }
                test.SetAttributeValue("NumberOfQuestions", ind);
                test.Add(question);
                test.Save(tempFileName + "test.xml");
                WriteImages(tempFileName + "test.xml");
                var text = XmlToHtml(tempFileName + "test.xml");

                using (var sw = new StreamWriter(tempFileName + "test.html"))
                {
                    sw.Write(text);
                }

                File.Copy(Directory.GetCurrentDirectory() + "\\Data\\style.css", tempFileName + "test\\style.css", true);
                File.Copy(Directory.GetCurrentDirectory() + "\\Data\\bg.jpg", tempFileName + "test\\bg.jpg", true);

                System.Diagnostics.Process.Start(tempFileName + "test.html");
            }
            catch (Exception ex)
            {
                Hider.Visibility = Visibility.Visible;
                OkMessage a = new OkMessage("Ошибка препросмотра", "При попытке препросмотра возникла ошибка.\n Message: " + ex.Message);
                a.ShowDialog();
                Hider.Visibility = Visibility.Hidden;
            }
        }
        private void WriteImages(string url)
        {
            int ind2 = url.Length - 1;
            while (url[ind2] != '\\')
            {
                ind2--;
            }
            string testname = url.Substring(ind2 + 1);


            ind2 = testname.IndexOf('.');

            string newurl = url.Replace(testname, "");

            TestName = testname.Substring(0, ind2);
            Directory.CreateDirectory(newurl + "\\" + testname.Substring(0, ind2));

            foreach (var image in Images)
            {
                int ind = image.Length - 1;
                while (image[ind] != '\\')
                {
                    ind--;
                }
                string filename = image.Substring(ind + 1);

                ind = image.Length - 1;
                while (image[ind] != '\\')
                {
                    ind--;
                }
                try
                {
                    File.Copy(image, newurl + "\\" + TestName + "\\" + filename, true);
                }
                catch (Exception ex)
                {
                    Hider.Visibility = Visibility.Visible;
                    OkMessage yn = new OkMessage("Ошибка копирования", "Изображение не найдено. Файл может отображаться некорекнто. \nОшибка \"" + ex.Message + "\"");
                    yn.ShowDialog();
                    Hider.Visibility = Visibility.Hidden;
                }
            }
        }
        private void MenuItem_Click_2(object sender, RoutedEventArgs e)
        {
            if (Questions.Items.Count == 0)
            {
                Hider.Visibility = Visibility.Visible;
                OkMessage yn = new OkMessage("Сохранение не удалось", "Тест не имеет ни одного вопроса. Такое сохранение не допустимо");
                yn.ShowDialog();
                Hider.Visibility = Visibility.Hidden;
                return;
            }

            var test = new XElement("Test");
            string filename = CurrentDirectory;
            if (string.IsNullOrEmpty(CurrentDirectory))
            {
                var sd = new SaveFileDialog();
                sd.Filter = "XML documents | *.xml";
                sd.ShowDialog();
                if (string.IsNullOrEmpty(sd.FileName)) return;
                test.SetAttributeValue("TestName", sd.FileName);
                filename = sd.FileName;
                CurrentFileName = filename;
            }

            var preambula = new XElement("Preambula");
            foreach (var item in Preambula)
            {
                var temp = new XElement("PreambulaItem");
                temp.SetAttributeValue("Name", item.Item1);
                temp.SetAttributeValue("Value", item.Item2);
                preambula.Add(temp);
            }
            test.Add(preambula);

            var question = new XElement("Question");
            int ind = 0;
            foreach (Question item in Questions.Items)
            {
                question.Add(QuestionToElement(item, ind));
                ind++;
            }
            test.SetAttributeValue("NumberOfQuestions", ind);
            test.Add(question);

            test.Save(CurrentFileName);

            WriteImages(CurrentFileName);
        }
        private void MenuItem_Click_19(object sender, RoutedEventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            of.ShowDialog();

            if (string.IsNullOrEmpty(of.FileName))
            {
                return;
            }
            var converter = new Converter();
            try
            {
                converter.Dowork(of.FileName, of.FileName + ".xml");
                Hider.Visibility = Visibility.Visible;
                OkMessage yn = new OkMessage("Преобразовано успешно", "Файл сохранен как " + of.FileName + ".xml");
                yn.ShowDialog();
                Hider.Visibility = Visibility.Hidden;
            }
            catch (Exception ex)
            {
                Hider.Visibility = Visibility.Visible;
                OkMessage yn = new OkMessage("Преобразование не удалось", "Ошибка анализа файла. Преобразование провалено, ошибка " + ex.Message);
                yn.ShowDialog();
                Hider.Visibility = Visibility.Hidden;
            }

        }