示例#1
0
        internal static void Format(string formatString, Collection <UIElement> items, Style textStyle, List <UIElement> formattedList)
        {
            StringBuilder text = new StringBuilder();

            for (int index1 = 0; index1 < formatString.Length; ++index1)
            {
                if ((int)formatString[index1] != 123)
                {
                    text.Append(formatString[index1]);
                }
                else
                {
                    ++index1;
                    if (index1 < formatString.Length && (int)formatString[index1] == 123)
                    {
                        text.Append('{');
                    }
                    else if (index1 >= formatString.Length || (int)formatString[index1] != 125)
                    {
                        FormattingControl.Emit(text, textStyle, formattedList);
                        text = new StringBuilder();
                        StringBuilder stringBuilder = new StringBuilder();
                        for (; index1 < formatString.Length && (int)formatString[index1] != 125; ++index1)
                        {
                            stringBuilder.Append(formatString[index1]);
                        }
                        int index2 = int.Parse(stringBuilder.ToString(), (IFormatProvider)CultureInfo.InvariantCulture);
                        formattedList.Add(items[index2]);
                    }
                }
            }
            FormattingControl.Emit(text, textStyle, formattedList);
        }
示例#2
0
        private void UpdatePanel()
        {
            Panel panel = this.GetTemplateChild("PART_Panel") as Panel;

            if (panel == null || this.Items.Count <= 0)
            {
                return;
            }
            List <UIElement> formattedList = new List <UIElement>();

            FormattingControl.Format(this.FormatString, this.Items, this.TextStyle, formattedList);
            if (formattedList.Count <= 0)
            {
                return;
            }
            panel.Children.Clear();
            foreach (UIElement element in formattedList)
            {
                panel.Children.Add(element);
            }
        }