WPF: How to change the background color of a TransitioningContentControl?

I work with MahApps, I use this content to show the license text read from a file.

    <controls:TransitioningContentControl Transition="Down" Content="{Binding LicenseDocument}" FontFamily="{DynamicResource ContentFontFamily}" FontSize="{DynamicResource NormalFontSize}" Visibility="{Binding LicenseInfoVisibility}" TabIndex="0" Margin="0,-5,0,10"/>

public FrameworkElement LicenseDocument
{
  get;
  set;
}
public void InitDoc()
{
    try
    {
        const string licenseFullFile = @"License.rtf";
        using (
            MemoryStream stream = new MemoryStream(Encoding.Default.GetBytes(File.ReadAllText(licenseFullFile)))
            )
        {
            FlowDocument document = new FlowDocument();
            new TextRange(document.ContentStart, document.ContentEnd).Load(stream, DataFormats.Rtf);
            RichTextBox box = new RichTextBox(document)
            {
                VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                IsReadOnly = true
            };
            LicenseInfoVisibility = Visibility.Visible;
            this.LicenseDocument = box;
        }
    }
    catch (Exception xException)
    {
        Debug.WriteLine(xException);
    }
}

It works fine when I use

<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />

Got my resourcedictionary

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
        <!--<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Cobalt.xaml" />-->
        <!--<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />-->
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
    </ResourceDictionary.MergedDictionaries>

But if I use BaseDark, then the background is richtext and the font colors will be black.

What's wrong?

+4
source share
1 answer

Make sure that License.rtfis foregroundset to automatically and backgroundat no color .

XAML:

<Controls:MetroWindow xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
                  xmlns:local="clr-namespace:MahApps.Metro.Application3" 
                  x:Class="MahApps.Metro.Application3.MainWindow"
                  Title="MainWindow"
                  Height="350"
                  Width="525">
<Controls:MetroWindow.DataContext>
    <local:MyViewModel/>
</Controls:MetroWindow.DataContext>

<Grid>
    <Controls:TransitioningContentControl Transition="Down" 
                                          Content="{Binding LicenseDocument}" 
                                          FontFamily="{DynamicResource ContentFontFamily}" 
                                          FontSize="{DynamicResource NormalFontSize}" 
                                          Visibility="{Binding LicenseInfoVisibility}" 
                                          TabIndex="0" Margin="0,-5,0,10"/>
</Grid>

Baselight:

enter image description here

BaseDark:

enter image description here

+2
source

Source: https://habr.com/ru/post/1623250/


All Articles