gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:24:08 26 4
gpt4 key购买 nike

我使用 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.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,则富文本背景和字体颜色为黑色。

怎么了?

最佳答案

确保 License.rtfforeground 设置为 Automatic 并将 background 设置为 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>

基础光源:

enter image description here

基础暗色:

enter image description here

关于c# - WPF:如何更改 TransitioningContentControl 背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34653142/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com