Exemplo n.º 1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (this.NavigationContext.QueryString.ContainsKey("user"))
            {
                string title = this.NavigationContext.QueryString["title"];
                if (title.Length > 3 && title.Substring(0, 3) == "Re:")
                {
                    TitleText.Text = title;
                }
                else
                {
                    TitleText.Text = "Re: " + title;
                }

                UserText.Text = this.NavigationContext.QueryString["user"];
                reid          = int.Parse(this.NavigationContext.QueryString["reid"]);

                ContentText.Focus();
            }
            else
            {
                UserText.Focus();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 光标所在处添加内容光标后移
        /// </summary>
        /// <param name="text"></param>
        public void CurrentWrite(string text)
        {
            var index = ContentText.CaretOffset;
            var str   = ContentText.Text;
            var str1  = str.Substring(0, index);
            var str2  = str.Substring(index);

            ContentText.Text        = str1 + text + str2;
            ContentText.CaretOffset = index + text.Length;
            ContentText.Focus();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 自动格式化
        /// </summary>
        /// <param name="editor"></param>
        public void AutoFormat()
        {
            var index = ContentText.CaretOffset;

            var text     = ContentText.Text;
            var tempkey  = "" + ((char)1);
            var tempkey2 = "" + ((char)2) + ((char)2);
            var tempkey3 = "" + ((char)3) + ((char)3);

            text = text.Replace("\\", tempkey);
            text = text.Replace(tempkey + tempkey, tempkey2);
            text = text.Replace(tempkey + "\"", tempkey3);
            var result = "";
            var strs   = text.Split('\"');
            var parse  = "";

            for (int i = 0; i < strs.Length; i += 1)
            {
                if (i % 2 == 1)
                {
                    result += "\"" + strs[i] + "\"";
                }
                else
                {
                    if (result.Length + strs[i].Length <= index)
                    {
                        var formatstr = Format(strs[i], ref parse);
                        index  += formatstr.Length - strs[i].Length;
                        result += formatstr;
                    }
                    else if (result.Length < index)
                    {
                        var str1      = strs[i].Substring(0, index - result.Length);
                        var str2      = strs[i].Substring(index - result.Length);
                        var formatstr = Format(str1, ref parse);
                        index += formatstr.Length - str1.Length;
                        if (formatstr.EndsWith("\n\n") && str2.StartsWith("\n"))
                        {
                            formatstr = formatstr.Substring(0, formatstr.Length - 1);
                            index    -= 1;
                        }
                        else if (formatstr.EndsWith(";\n") && str2.StartsWith("\n"))
                        {
                            formatstr = formatstr.Substring(0, formatstr.Length - 1);
                            index    -= 1;
                        }
                        result += formatstr;
                        result += Format(str2, ref parse);
                    }
                    else
                    {
                        result += Format(strs[i], ref parse);
                    }
                }
            }
            result = result.Replace(tempkey3, tempkey + "\"");
            result = result.Replace(tempkey2, tempkey + tempkey);
            result = result.Replace(tempkey, "\\");

            ContentText.Text = result;

            ContentText.CaretOffset = index;
            ContentText.Focus();
        }