private void button_Click(object sender, RoutedEventArgs e)
        {
            States.Clear();
            CurrentStateIndex = 0;


            NumberOfQuestions++;
            var question = new Question();
            question.Title = "Новый вопрос";
            question.Content = NumberOfQuestions + ". " + question.Title;
            question.Selected += Question_Selected;
            question.Number = NumberOfQuestions;
            question.Text = "[Difficulty = \"1\"]\nТекст вопроса";

            Questions.Items.Add(question);
            Questions.SelectedItem = question;

            MiddleEditor.IsEnabled = true;
        }
        private XElement QuestionToElement(Question src, int code)
        {
            var elements = SplitText(src.Text).Select(w => w.Replace("\n", "\n<br/>").Replace("\r", "").Replace("  ", "&nbsp;")).Where(w => w != "").ToArray();
            XElement a = new XElement("Question");
            a.SetAttributeValue("Code", code);
            a.SetAttributeValue("Difficulty", 1);
            var toq = new XElement("TextOfQuestion");
            var choise = new XElement("Choice");
            int ind = 0;
            toq.Add(TextToString(src.Title, ind));
            ind++;

            foreach (var item in elements)
            {
                // If text is come
                if (item[0] != '[')
                {
                    toq.Add(TextToString(item, ind));
                    ind++;
                    continue;
                }

                //If input is come
                if (item.Length >= 6 && item.Substring(0, 6) == "[Input")
                {
                    toq.Add(InputToString(item, ind));
                }

                //If Image is come
                if (item.Length >= 6 && item.Substring(0, 6) == "[Image")
                {
                    toq.Add(ImageToString(item, ind));
                }


                if (item.Length >= 7 && item.Substring(0, 7) == "[Choice")
                {
                    choise.Add(ChoiseToString(item));
                    ind--;
                }

                if (item.Length >= 11 && item.Substring(0, 11) == "[Difficulty")
                {
                    a.SetAttributeValue("Difficulty", GetValue(item, "Difficulty"));
                    ind--;
                }

                if (item.Length >= 20 && item.Substring(0, 20) == "[IndexOfNextQuestion")
                {
                    a.SetAttributeValue("IndexOfNextQuestion", GetValue(item, "Index"));
                    ind--;
                }

                ind++;
            }
            a.SetAttributeValue("NumberOfTexts", ind);
            a.Add(toq);
            a.Add(choise);
            return a;
        }
        private Question XmlToQuestion(XElement q, int id)
        {
            var question = new Question();
            var nextIndex = "";
            if (q.Attribute("IndexOfNextQuestion") != null)
            {
                nextIndex = "[IndexOfNextQuestion Index=\"" + q.Attribute("IndexOfNextQuestion").Value + "\"]";
            }
            question.Title = q.Descendants("TextOfQuestion").First().Element("TextOfQuestion").Attribute("SymplyText").Value.Trim();
            if (q.Attribute("Difficulty") != null)
            {
                question.Difficulty = Convert.ToInt32(q.Attribute("Difficulty").Value);
            }
            else
            {
                question.Difficulty = 1;
            }
            question.Content = NumberOfQuestions + ". " + RemakeTitle(question.Title);
            question.Selected += Question_Selected;
            question.Number = id;
            var text = "[Difficulty = \"" + question.Difficulty + "\"]\n" + nextIndex + "\n";


            //Adding toq
            var toq = q.Descendants("TextOfQuestion").First().Elements().Skip(1).ToArray();
            foreach (var item in toq)
            {
                text += ToqToText(item);
            }

            // Adding choice
            var ch = q.Descendants("Choice");
            if (ch.Count() != 0)
            {
                text += ChoiseToText(ch.First());
            }

            question.Text = text;
            return question;
        }