Skip to content

Instantly share code, notes, and snippets.

@KennethanCeyer
Created October 4, 2015 06:33
Show Gist options
  • Save KennethanCeyer/934881aafa0f9a73936f to your computer and use it in GitHub Desktop.
Save KennethanCeyer/934881aafa0f9a73936f to your computer and use it in GitHub Desktop.
How to Add more than two TextBlock object in ListBoxItem
ListBoxItem lb = new ListBoxItem();
DockPanel dp = new DockPanel();
TextBlock user = new TextBlock();
user.Text = data.name;
if(data.color != null)
{
user.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#" + data.color));
}
TextBlock tb = new TextBlock();
tb.TextWrapping = TextWrapping.Wrap;
tb.Text = message;
if (bnetChattingColor == BnetChattingColor.Error || bnetChattingColor == BnetChattingColor.Info || bnetChattingColor == BnetChattingColor.Whisper)
{
TextBlock status = new TextBlock();
Thickness statusMargin = status.Margin;
statusMargin.Right = 6;
status.Margin = statusMargin;
if (bnetChattingColor == BnetChattingColor.Error)
{
status.Text = "[에러]";
}
else if (bnetChattingColor == BnetChattingColor.Info)
{
status.Text = "[정보]";
}
else if (bnetChattingColor == BnetChattingColor.Whisper)
{
status.Text = "[귓속말]";
Thickness userMargin = user.Margin;
userMargin.Right = 6;
user.Margin = userMargin;
user.Text += ":";
}
dp.Children.Add(status);
} else
{
Thickness userMargin = user.Margin;
userMargin.Right = 6;
user.Margin = userMargin;
user.Text += ":";
}
dp.Children.Add(user);
dp.Children.Add(tb);
lb.Content = dp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment