Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Sample Applications/WPFGallery/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Configuration;
using System.Data;
using System.Windows;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

Expand Down Expand Up @@ -153,9 +154,24 @@ public static void Main()

App app = new();
app.InitializeComponent();
app.ApplyDeemphasizedTextOpacity();
app.MainWindow = _host.Services.GetRequiredService<MainWindow>();
app.MainWindow.Visibility = Visibility.Visible;
app.Run();
}

// Dimmed text fails the 4.5:1 minimum under some high-contrast themes (e.g. Desert), so render
// de-emphasized text at full opacity there. DynamicResource pushes the change to every consumer.
private void ApplyDeemphasizedTextOpacity()
{
Resources["DeemphasizedTextOpacity"] = SystemParameters.HighContrast ? 1.0 : 0.7;
SystemParameters.StaticPropertyChanged += (_, e) =>
{
if (e.PropertyName == nameof(SystemParameters.HighContrast))
{
Resources["DeemphasizedTextOpacity"] = SystemParameters.HighContrast ? 1.0 : 0.7;
}
};
}
}

4 changes: 4 additions & 0 deletions Sample Applications/WPFGallery/Resources/PageStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<sys:Double x:Key="TitleLargeTextBlockFontSize">40</sys:Double>
<sys:Double x:Key="DisplayTextBlockFontSize">68</sys:Double>

<!-- Opacity for de-emphasized text; App overrides it to 1.0 under high contrast so dimmed
text keeps the 4.5:1 minimum (e.g. the Desert contrast theme). -->
<sys:Double x:Key="DeemphasizedTextOpacity">0.7</sys:Double>

<Style x:Key="BaseTextBlockStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="{StaticResource BodyTextBlockFontSize}" />
<Setter Property="FontWeight" Value="SemiBold" />
Expand Down
2 changes: 1 addition & 1 deletion Sample Applications/WPFGallery/Resources/Templates.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Width="240"
Margin="10,0,0,0"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Opacity="0.7"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{Binding Description}"/>
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
This Source Code Form is subject to the terms of the MIT License.
If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
Copyright (C) Leszek Pomianowski and WPF UI Contributors.
Expand Down Expand Up @@ -104,7 +104,7 @@
Grid.Column="1"
Margin="12,0,0,6"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Opacity="0.7"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Text="{Binding Company, Mode=OneWay}" />
</Grid>
</DataTemplate>
Expand All @@ -115,7 +115,7 @@
MinWidth="120"
Margin="12,0,0,0"
VerticalAlignment="Top">
<Label Foreground="{DynamicResource TextFillColorPrimaryBrush}" Opacity="0.7" Content="Selection mode" Target="{Binding ElementName=SelectionModeComboBox}" />
<Label Foreground="{DynamicResource TextFillColorPrimaryBrush}" Opacity="{DynamicResource DeemphasizedTextOpacity}" Content="Selection mode" Target="{Binding ElementName=SelectionModeComboBox}" />
<ComboBox
x:Name="SelectionModeComboBox"
AutomationProperties.Name="Selection Mode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@
<TextBlock
Margin="16,0,0,0"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Opacity="0.7"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="Corner radius" />
<TextBlock
Grid.Column="1"
Margin="16,0,0,0"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Opacity="0.7"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="Usage" />
<TextBlock
Grid.Column="2"
Margin="16,0,0,0"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Opacity="0.7"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="Style" />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Page x:Class="WPFGallery.Views.IconsPage"
<Page x:Class="WPFGallery.Views.IconsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -22,7 +22,7 @@
<Setter Property="MinHeight" Value="32" />
<Setter Property="Padding" Value="0 0 0 4" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="Opacity" Value="0.7"/>
<Setter Property="Opacity" Value="{DynamicResource DeemphasizedTextOpacity}"/>
<Setter Property="Margin" Value="0,4,0,4" />
<Setter Property="FontSize" Value="14"/>
</Style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@
<TextBlock
Margin="16,0,0,0"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Opacity="0.7"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="Value" />
<TextBlock
Grid.Column="2"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Opacity="0.7"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="Usage" />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Page x:Class="WPFGallery.Views.TypographyPage"
<Page x:Class="WPFGallery.Views.TypographyPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand Down Expand Up @@ -59,25 +59,25 @@
<TextBlock
Margin="16,0,0,0"
Foreground="{StaticResource TextFillColorPrimaryBrush}"
Opacity="0.7"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="Example" />
<TextBlock
Grid.Column="1"
Foreground="{StaticResource TextFillColorPrimaryBrush}"
Opacity="0.7"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="Variable Font" />
<TextBlock
Grid.Column="2"
Foreground="{StaticResource TextFillColorPrimaryBrush}"
Opacity="0.7"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="Size/Line height" />
<TextBlock
Grid.Column="3"
Foreground="{StaticResource TextFillColorPrimaryBrush}"
Opacity="0.7"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="Style" />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Page
<Page
x:Class="WPFGallery.Views.UserDashboardPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -20,7 +20,7 @@
<helpers:EmptyToVisibilityConverter x:Key="EmptyToVisibilityConverter" />

<Style TargetType="Label" x:Key="GenericLabelStyle">
<Setter Property="Opacity" Value="0.67"/>
<Setter Property="Opacity" Value="{DynamicResource DeemphasizedTextOpacity}"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}"/>
</Style>
Expand Down Expand Up @@ -91,7 +91,7 @@
Grid.Column="1"
Margin="12,0,0,6"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Opacity="0.8"
Opacity="{DynamicResource DeemphasizedTextOpacity}"
Text="{Binding Company, Mode=OneWay}" />
</Grid>
</DataTemplate>
Expand Down
6 changes: 3 additions & 3 deletions Sample Applications/WPFGallery/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Page
<Page
x:Class="WPFGallery.Views.SettingsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down Expand Up @@ -57,7 +57,7 @@
Margin="12"
Orientation="Vertical">
<TextBlock Text="App theme" FontSize="14"/>
<TextBlock Opacity="0.7" FontSize="12" Style="{StaticResource CaptionTextBlockStyle}">Select which app theme to display</TextBlock>
<TextBlock Opacity="{DynamicResource DeemphasizedTextOpacity}" FontSize="12" Style="{StaticResource CaptionTextBlockStyle}">Select which app theme to display</TextBlock>
</StackPanel>


Expand Down Expand Up @@ -93,7 +93,7 @@
Margin="12"
Orientation="Vertical">
<TextBlock Text="WPF Gallery" />
<TextBlock Opacity="0.7" Style="{StaticResource CaptionTextBlockStyle}">© 2025 Microsoft. All rights reserved.</TextBlock>
<TextBlock Opacity="{DynamicResource DeemphasizedTextOpacity}" Style="{StaticResource CaptionTextBlockStyle}">© 2025 Microsoft. All rights reserved.</TextBlock>
</StackPanel>
</Grid>
</Expander.Header>
Expand Down
6 changes: 3 additions & 3 deletions Sample Applications/WPFGallery/Views/Text/LabelPage.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
This Source Code Form is subject to the terms of the MIT License.
If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
Copyright (C) Leszek Pomianowski and WPF UI Contributors.
Expand Down Expand Up @@ -32,7 +32,7 @@
Margin="10"
HeaderText="A simple Label."
XamlCode="&lt;Label Content=&quot;I am a Label.&quot; /&gt;">
<Label Content="I am a Label." Foreground="{DynamicResource TextFillColorPrimaryBrush}" Opacity="0.7" />
<Label Content="I am a Label." Foreground="{DynamicResource TextFillColorPrimaryBrush}" Opacity="{DynamicResource DeemphasizedTextOpacity}" />
</controls:ControlExample>

<controls:ControlExample
Expand All @@ -44,7 +44,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="I am a Label of the TextBox below." Foreground="{DynamicResource TextFillColorPrimaryBrush}" Opacity="0.7" />
<Label Grid.Row="0" Content="I am a Label of the TextBox below." Foreground="{DynamicResource TextFillColorPrimaryBrush}" Opacity="{DynamicResource DeemphasizedTextOpacity}" />
<!-- Target="{Binding ElementName=TextBoxForLabel}" -->
<TextBox Grid.Row="1" AutomationProperties.Name="Simple Text Box" />
</Grid>
Expand Down
Loading