Kryptos-FR / markdig.wpf

A WPF library for xoofx/markdig https://github.com/xoofx/markdig
MIT License
159 stars 50 forks source link

Heading color does not change. #24

Closed Tum4ik closed 5 years ago

Tum4ik commented 5 years ago

image

<UserControl ...
             Loaded="LicenseDialog_OnLoaded">
  <FlowDocumentScrollViewer x:Name="FlowDocumentScrollViewer" />
</UserControl>
private void LicenseDialog_OnLoaded(object sender, RoutedEventArgs e)
{
    var licenseContent = File.ReadAllText("License.md");
    var flowDocument = Markdown.ToFlowDocument(licenseContent);
    flowDocument.Foreground = Brushes.White;
    FlowDocumentScrollViewer.Document = flowDocument;
}

License.md

### License

Test license.
**Test license.**
Test license.
Test license.
...
Kryptos-FR commented 5 years ago

Headings use styles. So you need to update/override those.

See https://github.com/Kryptos-FR/markdig.wpf/blob/develop/src/Markdig.Wpf/Themes/generic.xaml

Tum4ik commented 5 years ago

Yep, that's it. Thanks!

Otiel commented 5 years ago

Should this style really override the Foreground color?

<Style TargetType="{x:Type Paragraph}" x:Key="{x:Static markdig:Styles.Heading1StyleKey}">
    <Setter Property="FontSize" Value="42" />
    <Setter Property="Foreground" Value="#ff000000" />
    <Setter Property="FontWeight" Value="Bold" />
</Style>

Why not use the default Foreground value?


Can you advise on how to override this style? I've got the following error when trying:

<Style TargetType="{x:Type markdig:Styles.Heading1StyleKey}">
    ...
</Style>

Nested types are not supported: Styles.Heading1StyleKey.

Tum4ik commented 5 years ago

@Otiel , I've created a separate resource dictionary file and define the style there like:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf">
...
<Style TargetType="{x:Type Paragraph}" x:Key="{x:Static markdig:Styles.Heading2StyleKey}">
    <Setter Property="FontSize" Value="20" />
    <Setter Property="Foreground" Value="#FF007ACC" />
    <Setter Property="FontWeight" Value="Bold" />
</Style>
...
</ResourceDictionary>
Otiel commented 5 years ago

Thanks, exactly what I needed!