コード例 #1
0
        /// <summary>
        /// 指定字符串转换为指定进制的数字形式,
        /// 显示内容的位置就是模,
        /// 位数就倍数
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public long FromString(string str)
        {
            long result = 0;
            int  j      = 0;

            foreach (var ch in str.ToCharArray().Reverse().ToArray())
            {
                if (FormatString.Contains(ch))
                {
                    result += FormatString.IndexOf(ch) * ((long)Math.Pow(Length, j));
                    j++;
                }
            }
            return(result);
        }
コード例 #2
0
        // Constructs the formatted text
        private void buildBlocks()
        {
            if (AssociatedObject == null || FormatString == null || Values == null)
            {
                return;
            }

            int       i    = 0;
            int       last = 0;
            Paragraph p    = new Paragraph();

            // Loop through each value
            while (i <= Values.Count)
            {
                // Get the index of the current substitution placeholder in the format string
                int current = FormatString.IndexOf("{" + i + "}");

                // Get the section of the format string between the last placeholder and the current one
                string subSection = i < Values.Count || current >= 0 ?
                                    FormatString.Substring(last, current - last) : FormatString.Substring(last);

                // Add the section to the formatted text
                if (!string.IsNullOrEmpty(subSection))
                {
                    p.Inlines.Add(new Run()
                    {
                        Text = subSection
                    });
                }

                // If the last value has already been processed, exit
                if (i == Values.Count || current < 0)
                {
                    break;
                }

                // Get the value and add it to the formatted text
                object val = Values[i];
                if (val is string)
                {
                    p.Inlines.Add(new Run()
                    {
                        Text = (string)val
                    });
                }
                else if (val is Inline)
                {
                    p.Inlines.Add((Inline)val);
                }
                else if (val is UIElement)
                {
                    p.Inlines.Add(new InlineUIContainer()
                    {
                        Child = (UIElement)val
                    });
                }

                last = current + 3;
                i++;
            }

            // Update the associated RichTextBlock's content
            AssociatedObject.Blocks.Clear();
            AssociatedObject.Blocks.Add(p);
        }