Remove the color formatting from your C#
code and put this in your App.xaml
file:
<Application.Resources>
...
<TextDecorationCollection x:Key="_textDeco_hyperlink">
<!--<TextDecoration Location="Underline" />-->
</TextDecorationCollection>
<Style TargetType="{x:Type Hyperlink}">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Background" Value="Khaki" />
<Setter Property="ForceCursor" Value="True" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="TextDecorations" Value="{DynamicResource _textDeco_hyperlink}" />
<Setter Property="IsEnabled" Value="False" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Khaki" />
<Setter Property="Background" Value="Black" />
</Trigger>
</Style.Triggers>
</Style>
...
<Application.Resources>
If this is not working I think it's the way how you serialize and deserialize your FlowDocument
.
Try this:
// Store your FlowDocument as a list of strings
List<string> blocksAsStrings = FlowDoc_store(_docSelected._Rtb.Document);
...
// Load your FlowDocument into your RichTextBox
rtb.Document = FlowDoc_load(blocksAsStrings);
/// <summary>
/// Stores a FlowDocument as a list of strings, each string represents a Block.
/// </summary>
public static List<string> FlowDoc_store(FlowDocument flowDoc)
{
List<string> blocksAsStrings = new List<string>(flowDoc.Blocks.Count);
foreach (Block block in flowDoc.Blocks)
{
blocksAsStrings.Add(XamlWriter.Save(block));
}
return blocksAsStrings;
}
/// <summary>
/// Loads a FlowDocument from a list of strings, each string represents a Block.
/// </summary>
public static FlowDocument FlowDoc_load(List<string> blocksAsStrings)
{
FlowDocument flowDoc = new FlowDocument();
foreach (string blockAsString in blocksAsStrings)
{
using (StringReader stringReader = new StringReader(blockAsString))
{
using (XmlReader xmlReader = XmlReader.Create(stringReader))
{
Block block = (Block)XamlReader.Load(xmlReader);
flowDoc.Blocks.Add(block);
}
}
}
return flowDoc;
}