Exemplo n.º 1
0
            private void AppendText(ListBoxItem item, StackPanel panel, string message, string category)
            {
                Debug.Assert(item.Content == panel);

                string firstLine = GetFirstLine(message);

                if (firstLine == message)
                {
                    TextBlock textBlock = new TextBlock();
                    textBlock.Text = message;
                    ApplyFont(textBlock, category);
                    panel.Children.Add(textBlock);

                    if (item.Tag == null)
                    {
                        item.Tag = message;
                    }
                    else
                    {
                        item.Tag = (string)item.Tag + message;
                    }
                }
                else
                {
                    Button button = new Button();
                    button.Content = firstLine;
                    button.Click  += new RoutedEventHandler((sender, e) =>
                    {
                        ConsoleHtmlBox htmlBox = new ConsoleHtmlBox(message);
                        htmlBox.Show();
                    });
                    ApplyFont(button, category);
                    panel.Children.Add(button);

                    if (item.Tag == null)
                    {
                        item.Tag = firstLine;
                    }
                    else
                    {
                        item.Tag = (string)item.Tag + firstLine;
                    }
                }
            }
Exemplo n.º 2
0
            private void AppendElement(ListBoxItem item, StackPanel panel, object o, string category)
            {
                Debug.Assert(item.Content == panel);

                if (o is Exception)
                {
                    Exception ex = (Exception)o;

                    string text   = string.Format("{0} Thrown ({1})", ex.GetType().Name, GetFirstLine(ex.Message));
                    Button button = new Button();
                    button.Content = text;
                    button.Click  += new RoutedEventHandler((sender, e) =>
                    {
                        ConsoleHtmlBox htmlBox = new ConsoleHtmlBox(ex.ToString());
                        htmlBox.Show();
                    });
                    ApplyFont(button, "EXCEPTION");

                    panel.Children.Add(button);
                    if (item.Tag == null)
                    {
                        item.Tag = text;
                    }
                    else
                    {
                        item.Tag = (string)item.Tag + text;
                    }

                    window.Activate();
                    window.Topmost = true;
                    window.Topmost = false;
                    window.Focus();
                    System.Media.SystemSounds.Exclamation.Play();
                }
                else
                {
                    AppendText(item, panel, o.ToString(), category);
                }
            }