WPF:如何更改TransitioningContentControl背景颜色?

时间:2016-01-07 10:45:07

标签: c# wpf xaml mahapps.metro

我使用MahApps,使用此内容控件显示从文件中读取的许可证文本。

    <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);
    }
}

使用

时可以正常工作
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />

有我的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>

但是如果我使用BaseDark那么richtext背景和字体颜色是黑色的。

有什么问题?

1 个答案:

答案 0 :(得分:2)

确保License.rtf foreground设置为自动background设置为无颜色

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