如何让所有控件的前景色默认为白色
How to make Foreground color of all controls White by default
1- 创建一个新的 WPF 应用程序。
2- 向您的 WPF 应用程序添加一些控件。
3- 查看所有控件的前景色默认为黑色。
如何让所有控件的前景色默认为白色?
您可以尝试在 window 的 XAML 或 App.xaml
:
中定义隐式 TextBox
样式
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="300" Width="300">
<Window.Resources>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="White" />
</Style>
</Window.Resources>
...
这可能是您最接近于在一处设置所有控件的文本颜色的方法。
"Foreground color of all controls are Black by default."因为是Windows主题设置。
您可以使用 ControlTextBrushKey
键指定您自己的前景笔刷
<Application.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey }" Color="Green"/>
</Application.Resources>
此设置将立即在 属性 网格中的设计器中看到
1- 创建一个新的 WPF 应用程序。
2- 向您的 WPF 应用程序添加一些控件。
3- 查看所有控件的前景色默认为黑色。
如何让所有控件的前景色默认为白色?
您可以尝试在 window 的 XAML 或 App.xaml
:
TextBox
样式
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="300" Width="300">
<Window.Resources>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="White" />
</Style>
</Window.Resources>
...
这可能是您最接近于在一处设置所有控件的文本颜色的方法。
"Foreground color of all controls are Black by default."因为是Windows主题设置。
您可以使用 ControlTextBrushKey
键指定您自己的前景笔刷
<Application.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey }" Color="Green"/>
</Application.Resources>
此设置将立即在 属性 网格中的设计器中看到