WPF:如何更改 TransitioningContentControl 背景颜色?
WPF: How to change TransitioningContentControl background color?
我使用 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.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>
基础光源:
基础暗色:
我使用 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.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>
基础光源:
基础暗色: