tags:

views:

52

answers:

1

I'm trying to add inlines to a text block using the code below. The text block's window uses a Themes.xaml file for styling, but when I add the runs dynamically, the styling does not get applied. Can you help me understand why?

foreach (string key in wrappingOptions.Keys)
{
  Hyperlink link = new Hyperlink(new Run(key));
  string s = new string(wrappingOptions[key].ToCharArray());
  link.Click += (o, _) => tbIn.SelectedText = string.Format("<{0}>{1}</{0}>",
    s, tbIn.SelectedText);
  InputLinksBlock.Inlines.Add(link);
}
+2  A: 

Hyperlink is a FrameworkContentElement class. It does not derive it's text display properties from the parent TextBlock. You explicitly need to set a default style for a Hyperlink using <Style TargetType="Hyperlink">.

Yogesh