Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b84d534c2e |
No files matched your search
@@ -28,6 +28,17 @@ numeric core and does not move; the heading is the full version — corrected 20
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- **Page titles and section headings read in the dark theme again.** Every page's title and its section headings — Dashboard,
|
||||
Recent sessions, Games, Compare, Settings and each of its groups, Logs — were drawn near-black on the dark window
|
||||
(owner's screenshots of beta.17; beta.16 had it too). A page is shown in WPF UI's navigation Frame, which passes no text
|
||||
colour into the page, and a text that sets none is black; a page open during a theme switch picked the right colour up,
|
||||
and the next one navigated to did not. Every page now sets the theme's text colour itself. `AccessibilityTests.EveryPageSetsItsOwnTextColour`
|
||||
and `PagesLoadTests.EveryTextIsReadableInBothThemes` (every surface hosted as the App hosts it, ≥ 3:1 in both themes)
|
||||
went red on the unfixed pages first; the theme-switch check now hosts pages in the Frame too, and its harness derives the
|
||||
accent for each theme as the App does (`docs/08_UI.md` §Contrast, `docs/16_WPFUI_SYNTAX.md` §Gotchas, `docs/14_TESTING.md`).
|
||||
|
||||
## [0.1.0-beta.17] - 2026-10-07
|
||||
|
||||
**The seventeenth pre-release: text that keeps up with a change of theme, scroll bars hidden everywhere when you ask, a
|
||||
|
||||
@@ -845,6 +845,20 @@ palette per theme, chosen with the theme).
|
||||
> summary, every dialog's content and the safety InfoBar, made under one theme, switched, and compared text by text with
|
||||
> the same surface made fresh under the other — both ways). Both went red on the unfixed XAML, the second with 146 stale
|
||||
> texts each way, before they went green.
|
||||
>
|
||||
> **A fifth hole, closed 2026-10-07 (beta.18; the owner's screenshots of beta.17 in the dark theme: every page's title and
|
||||
> section headings near-black on the dark window — beta.16's screenshot shows it too).** This text had no colour of ours,
|
||||
> because it had none. A page is shown in WPF UI's `NavigationViewContentPresenter`, a `Frame`, and a Frame passes no
|
||||
> inherited value into its page (`InheritanceBehavior.SkipToAppNow`), so a text that sets no colour falls to the TextBlock
|
||||
> default, which WPF UI 4.3.0 makes black (`16_WPFUI_SYNTAX` §Gotchas). Cards, grids and controls set their own; the bare
|
||||
> titles and headings did not: 19 texts on the six pages at 1.29:1. Every check above laid a page out straight in a
|
||||
> window, whose text colour the page then inherited — a page the App never draws — and a page on screen during a theme
|
||||
> switch did take the window's colour, while each navigation makes a new one that does not, so it came and went. Every
|
||||
> page sets `Foreground="{DynamicResource TextFillColorPrimaryBrush}"` on its root. Held two ways:
|
||||
> `AccessibilityTests.EveryPageSetsItsOwnTextColour`, and `PagesLoadTests.EveryTextIsReadableInBothThemes` — every
|
||||
> surface hosted as the App hosts it, a page in the presenter, and every text that shows ≥ 3:1 over the colour painted
|
||||
> under it, in both themes. `EveryTextFollowsAThemeSwitch` hosts its pages in the presenter too since, and went red with
|
||||
> them: a page made after a switch stayed black. All three went red on the unfixed XAML before they went green.
|
||||
|
||||
### DPI
|
||||
|
||||
|
||||
@@ -71,6 +71,19 @@ under the new theme. `PagesLoadTests.Surfaces` builds every page, window and dia
|
||||
any check that wants all of them. Colours are compared and texts only reported: another test class may change
|
||||
`Strings.Culture` between the two builds.
|
||||
|
||||
**A page is measured in the Frame the App shows it in, and a theme brings its accent (beta.18).** WPF UI's
|
||||
`NavigationViewContentPresenter` is a `Frame`, which passes no inherited value into the page, the text colour included, so
|
||||
a page laid out straight in a window measures the window's colour and not the App's: the theme-switch check above did, and
|
||||
stayed green over every page title drawn black (`08_UI` §Contrast, fifth hole). The rendered checks host a page in the
|
||||
presenter (`PagesLoadTests.Hosted`), and `PagesLoadTests.EveryTextIsReadableInBothThemes` measures every surface's shown
|
||||
texts at ≥ 3:1 in both themes. `Visuals.UnderTheme` switches as the App does — the accent resources derived for the theme
|
||||
from Windows' default accent (`Visuals.DefaultAccent`, the App's derivation rather than the machine's own palette), then
|
||||
the dictionary — and puts the application's own resources back afterwards. The accent lives in `Application.Resources`,
|
||||
not in a theme dictionary; until then a check under Light measured the dark theme's link blue on the light window, 1.9:1,
|
||||
a colour the App never shows. The theme-switch check compares what can be seen: a text only one of the two instances holds
|
||||
counts where it shows, and a collapsed part is not compared (a switch re-applies the template of a DataGrid's idle scroll
|
||||
bar, and its glyphs exist in the switched instance only).
|
||||
|
||||
**Loaded needs a shown window, and even then it is not raised everywhere (beta.17).** A tree laid out by hand never raises
|
||||
Loaded, and a shown one raises it only where a subtree listens for it (`16_WPFUI_SYNTAX` §Gotchas) — so a test that calls
|
||||
`RaiseEvent(Loaded)` proves a handler, never that WPF reaches it. `ScrollBarHidingTests.EverySurfaceShownWithTheOptionOnDrawsNoBar`
|
||||
|
||||
@@ -152,6 +152,8 @@ Native `Menu`, `TabControl`, `ComboBox`, `Slider`~~, `ListView`~~ are fine — t
|
||||
styles (`Styles/FrameLedger.xaml`), or the `Pill` style with a `SystemFillColor*BackgroundBrush` and an explicit text
|
||||
brush; `ContrastTests` refuses all five (`08_UI` §Contrast).
|
||||
- Do **not** set `Background` on `FluentWindow` (kills Mica). Page backgrounds transparent by default.
|
||||
- **Every `Page` root sets `Foreground="{DynamicResource TextFillColorPrimaryBrush}"`** (2026-10-07): the navigation's
|
||||
Frame passes no text colour into a page, and a text with none is black (§Gotchas).
|
||||
- Exception to the no-hex rule: the chart palette — defined once per theme in ~~`Styles/ChartPalette.xaml` (two dictionaries)~~ `Styles/ChartPalette.Dark.xaml` and `ChartPalette.Light.xaml` (corrected 2026-10-04), never inline.
|
||||
|
||||
## FlowDocument (rendered documents, beta.12)
|
||||
@@ -280,3 +282,14 @@ On startup and on `ApplicationThemeManager.Changed`: for every live plot set fig
|
||||
`DynamicResource`). `ContrastTests.NoTextBlockTakesItsColourFromAppearance` refuses every form in the App's XAML and code,
|
||||
`PagesLoadTests.EveryTextFollowsAThemeSwitch` renders every surface through a switch both ways, and
|
||||
`PagesLoadTests.WpfUisAppearanceStillKeepsTheThemeATextWasMadeUnder` turns red the day upstream follows a switch.
|
||||
- [ ] **A page in the `NavigationView` inherits nothing, its text colour included.** `NavigationViewContentPresenter` is a
|
||||
`Frame`, and `Frame` sets `InheritanceBehavior.SkipToAppNow`: the window's `Foreground` stops there, and a text that sets
|
||||
no colour falls to the TextBlock default, which WPF UI 4.3.0's `TextBlockMetadata` makes `Brushes.Black`. Cards, grids
|
||||
and controls set their own colour in their templates; the bare texts did not — every page's title and section headings
|
||||
were black on the dark window, 1.3:1 (the owner's screenshots of beta.17; beta.16's show it too). It came and went: a
|
||||
page on screen during a theme switch did take the window's new colour through the switch, and every navigation makes a
|
||||
new page that does not. Every `Page` root sets `Foreground="{DynamicResource TextFillColorPrimaryBrush}"`
|
||||
(`AccessibilityTests.EveryPageSetsItsOwnTextColour`). A check that lays a page out straight in a window measures the
|
||||
window's colour, not the App's — beta.17's theme-switch check did and was green over the black titles — so the rendered
|
||||
checks host a page in the presenter, and `PagesLoadTests.EveryTextIsReadableInBothThemes` measures every surface so
|
||||
hosted at ≥ 3:1 in both themes.
|
||||
@@ -9,6 +9,7 @@
|
||||
xmlns:vm="clr-namespace:FrameLedger.App.ViewModels"
|
||||
xmlns:charts="clr-namespace:FrameLedger.App.Charts"
|
||||
Title="{x:Static res:Strings.Compare_Header}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
ScrollViewer.CanContentScroll="False">
|
||||
<!-- 08_UI §Compare: the picker (2–5, cross-game), the overlaid percentile curves, the stat table; FR-6.2's guard is the view model's. -->
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
xmlns:vm="clr-namespace:FrameLedger.App.ViewModels"
|
||||
xmlns:controls="clr-namespace:FrameLedger.App.Controls"
|
||||
Title="{x:Static res:Strings.Dashboard_Header}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
ScrollViewer.CanContentScroll="False">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Style="{StaticResource PageRoot}">
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
xmlns:controls="clr-namespace:FrameLedger.App.Controls"
|
||||
xmlns:charts="clr-namespace:FrameLedger.App.Charts"
|
||||
Title="{x:Static res:Strings.Games_Header}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
ScrollViewer.CanContentScroll="False">
|
||||
<!--
|
||||
08_UI §Games › Game detail. The two rows — Supports (files on disk) and Last session measured (the
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
Title="{x:Static res:Strings.Games_Header}"
|
||||
AllowDrop="True"
|
||||
Drop="OnDrop"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
ScrollViewer.CanContentScroll="False">
|
||||
<!--
|
||||
08_UI §Games: search, sort, FR-1.1 add by pick or by dropping an .exe here. Since beta.11 (owner requests 2026-10-03):
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
xmlns:res="clr-namespace:FrameLedger.App"
|
||||
xmlns:vm="clr-namespace:FrameLedger.App.ViewModels"
|
||||
Title="{x:Static res:Strings.Logs_Header}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
ScrollViewer.CanContentScroll="False">
|
||||
<Grid Margin="24,16,24,16">
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
xmlns:res="clr-namespace:FrameLedger.App"
|
||||
xmlns:vm="clr-namespace:FrameLedger.App.ViewModels"
|
||||
Title="{x:Static res:Strings.Settings_Header}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
ScrollViewer.CanContentScroll="False">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel Style="{StaticResource PageRoot}">
|
||||
|
||||
@@ -185,6 +185,24 @@ public sealed class AccessibilityTests
|
||||
wrapped.Should().BeEmpty("a page without ScrollViewer.CanContentScroll=\"False\" is wrapped in WPF UI's scroller, and its own root swallows the wheel");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// beta.18 (the owner's screenshots of beta.17 in the dark theme: every page's title near-black on the dark window). A
|
||||
/// page is shown in WPF UI's <c>NavigationViewContentPresenter</c>, a <c>Frame</c>, and a Frame sets
|
||||
/// <c>InheritanceBehavior.SkipToAppNow</c>: the window's text colour never reaches the page, and a text with no colour
|
||||
/// of its own is WPF UI's TextBlock default, black. Every page gives its texts the theme's colour itself.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void EveryPageSetsItsOwnTextColour()
|
||||
{
|
||||
List<string> pages = [.. AppXaml().Where(static x => string.Equals(x.Xaml.Root!.Name.LocalName, "Page", StringComparison.Ordinal)).Select(static x => x.File)];
|
||||
List<string> uncoloured = [.. AppXaml().Where(static x => string.Equals(x.Xaml.Root!.Name.LocalName, "Page", StringComparison.Ordinal)
|
||||
&& !string.Equals(x.Xaml.Root.Attribute("Foreground")?.Value, "{DynamicResource TextFillColorPrimaryBrush}", StringComparison.Ordinal))
|
||||
.Select(static x => x.File)];
|
||||
|
||||
pages.Should().HaveCountGreaterThanOrEqualTo(6);
|
||||
string.Join(", ", uncoloured).Should().BeEmpty("a Frame passes no text colour into a page: each sets Foreground=\"{DynamicResource TextFillColorPrimaryBrush}\" (16_WPFUI_SYNTAX §Gotchas)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A stock <c>ScrollViewer</c> takes every wheel, even with nothing left to scroll; inside a dialog that scrolls, the wheel
|
||||
/// then stops at it. WPF UI's <c>PassiveScrollViewer</c> hands the wheel on at its ends (beta.14).
|
||||
|
||||
@@ -23,13 +23,6 @@ public sealed class ContrastTests
|
||||
{
|
||||
private static readonly string[] _paletteAppearances = ["Info", "Caution", "Danger", "Success"];
|
||||
|
||||
/// <summary>
|
||||
/// Windows' default accent. The accent brushes are not in the theme dictionaries: `ApplicationThemeManager.Apply(…,
|
||||
/// updateAccent: true)` derives them from the system accent at start-up (`MainWindow`), so the test derives them the
|
||||
/// same way from a fixed colour and measures WPF UI's own on-accent text against them.
|
||||
/// </summary>
|
||||
private static readonly Color _defaultAccent = Color.FromRgb(0x00, 0x78, 0xD4);
|
||||
|
||||
[Fact]
|
||||
public void NoBadgeUsesAPaletteAppearance()
|
||||
{
|
||||
@@ -143,10 +136,12 @@ public sealed class ContrastTests
|
||||
[InlineData(ApplicationTheme.Light)]
|
||||
public async Task EveryPillPairMeetsAAInBothThemes(ApplicationTheme theme)
|
||||
{
|
||||
Dictionary<string, double> ratios = await PagesLoadTests.OnStaAsync(() =>
|
||||
// The accent brushes are not in the theme dictionaries: the App derives them from the system accent at each theme
|
||||
// switch, and Visuals.UnderTheme derives them the same way from Windows' default accent. Until 2026-10-07 this
|
||||
// passed systemAccentColor: true, which reads the machine's own accent palette wherever Windows answers.
|
||||
Dictionary<string, double> ratios = await PagesLoadTests.OnStaAsync(() => Visuals.UnderTheme(theme, () =>
|
||||
{
|
||||
var themed = new ThemesDictionary { Theme = theme };
|
||||
ApplicationAccentColorManager.Apply(_defaultAccent, theme, systemGlassColor: false, systemAccentColor: true);
|
||||
Color window = Wcag.Resolve(themed, "ApplicationBackgroundColor");
|
||||
Color card = Wcag.Over(Wcag.Resolve(themed, "CardBackgroundFillColorDefault"), window);
|
||||
Color pillOff = Wcag.Over(Wcag.Resolve(themed, "ControlFillColorDefault"), card);
|
||||
@@ -159,7 +154,7 @@ public sealed class ContrastTests
|
||||
["qualifier warning: primary text on caution"] = Wcag.Ratio(Wcag.Over(Wcag.Resolve(themed, "TextFillColorPrimary"), caution), caution),
|
||||
["the Info badge, for the record"] = Wcag.Ratio(Wcag.Over(Wcag.Resolve(themed, "TextFillColorPrimary"), PaletteLightBlue()), PaletteLightBlue()),
|
||||
};
|
||||
});
|
||||
}));
|
||||
|
||||
using (new FluentAssertions.Execution.AssertionScope(theme.ToString()))
|
||||
{
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
||||
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using FluentAssertions;
|
||||
using Wpf.Ui.Appearance;
|
||||
using Wpf.Ui.Markup;
|
||||
|
||||
namespace FrameLedger.App.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Every text the App shows is readable in both themes (beta.18, the owner's screenshots of beta.17 in the dark theme: each
|
||||
/// page's title and section headings near-black on the dark window). Each surface is hosted as the App hosts it
|
||||
/// (<see cref="Hosted"/>): a page in WPF UI's <c>NavigationViewContentPresenter</c>, which is a <c>Frame</c>, and a Frame
|
||||
/// sets <c>InheritanceBehavior.SkipToAppNow</c> — nothing above it, the window's text colour included, reaches the page. A
|
||||
/// text with no colour of its own then falls back to the TextBlock default, which WPF UI 4.3.0's <c>TextBlockMetadata</c>
|
||||
/// sets to black. Text inside a card or a grid never showed it: their templates set a colour. The theme-switch check could
|
||||
/// not see it either: it compares a switched surface with a fresh one, and black was black in both.
|
||||
/// </summary>
|
||||
public sealed partial class PagesLoadTests
|
||||
{
|
||||
/// <summary>WCAG's minimum for large text and for what a user must make out; black on the dark window is 1.3.</summary>
|
||||
private const double _readableAtLeast = 3.0;
|
||||
|
||||
[Theory]
|
||||
[InlineData(ApplicationTheme.Dark)]
|
||||
[InlineData(ApplicationTheme.Light)]
|
||||
public async Task EveryTextIsReadableInBothThemes(ApplicationTheme theme)
|
||||
{
|
||||
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
||||
using Surfaces surfaces = await Surfaces.LoadAsync(s);
|
||||
|
||||
(int Texts, List<string> Faint) result = await OnStaAsync(() => Visuals.UnderTheme(theme, () =>
|
||||
{
|
||||
Color window = Wcag.Resolve(new ThemesDictionary { Theme = theme }, "ApplicationBackgroundColor");
|
||||
int texts = 0;
|
||||
var faint = new List<string>();
|
||||
foreach ((string name, Func<FrameworkElement> build) in surfaces.All())
|
||||
{
|
||||
(Window host, FrameworkElement root) = Hosted(build);
|
||||
try
|
||||
{
|
||||
Lay(root);
|
||||
foreach (TextBlock text in ShownTexts(root))
|
||||
{
|
||||
texts++;
|
||||
Color under = Visuals.PaintedUnder(text, root, window);
|
||||
double ratio = Wcag.Ratio(Visuals.TextOver(text, under), under);
|
||||
if (ratio < _readableAtLeast)
|
||||
{
|
||||
faint.Add(string.Create(CultureInfo.InvariantCulture, $"{name}: \"{text.Text}\" {ratio:0.00}:1 ({text.Foreground} on {under})"));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
host.Close();
|
||||
}
|
||||
}
|
||||
|
||||
return (texts, faint);
|
||||
}));
|
||||
|
||||
result.Texts.Should().BeGreaterThan(300, "every surface was rendered and holds text");
|
||||
string.Join(Environment.NewLine, result.Faint).Should().BeEmpty($"every text the App shows reads at {_readableAtLeast}:1 or better in the {theme} theme");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The non-empty texts under <paramref name="root"/> that a user can see and is meant to read: no collapsed or hidden
|
||||
/// element above them, and none disabled (WCAG asks nothing of an inactive control's text).
|
||||
/// </summary>
|
||||
private static IEnumerable<TextBlock> ShownTexts(DependencyObject root)
|
||||
{
|
||||
if (root is UIElement { Visibility: not Visibility.Visible } or UIElement { IsEnabled: false })
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (root is TextBlock { Text.Length: > 0 } text && text.Foreground is SolidColorBrush)
|
||||
{
|
||||
yield return text;
|
||||
}
|
||||
|
||||
int count = VisualTreeHelper.GetChildrenCount(root);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
foreach (TextBlock child in ShownTexts(VisualTreeHelper.GetChild(root, i)))
|
||||
{
|
||||
yield return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,17 +121,22 @@ public sealed partial class PagesLoadTests
|
||||
try
|
||||
{
|
||||
Lay(fresh);
|
||||
List<(string Path, string Text, string Colour)> before = Texts(switched);
|
||||
List<(string Path, string Text, string Colour)> after = Texts(fresh);
|
||||
if (before.Count != after.Count)
|
||||
{
|
||||
return (before.Count, [$"{name}: {before.Count} texts after the switch, {after.Count} in a fresh one"]);
|
||||
}
|
||||
List<DrawnText> before = Texts(switched);
|
||||
List<DrawnText> after = Texts(fresh);
|
||||
Dictionary<string, DrawnText> lived = before.ToDictionary(static d => d.Path, StringComparer.Ordinal);
|
||||
Dictionary<string, DrawnText> made = after.ToDictionary(static d => d.Path, StringComparer.Ordinal);
|
||||
|
||||
// Texts are reported, never compared: another test class may change Strings.Culture between the two builds.
|
||||
List<string> stale = [.. before.Zip(after)
|
||||
.Where(static p => !string.Equals(p.First.Path, p.Second.Path, StringComparison.Ordinal) || !string.Equals(p.First.Colour, p.Second.Colour, StringComparison.Ordinal))
|
||||
.Select(p => $"{name}: \"{p.First.Text}\" is {p.First.Colour}, made fresh {p.Second.Colour} ({p.First.Path})")];
|
||||
// Texts are reported, never compared: another test class may change Strings.Culture between the two builds. What is
|
||||
// compared is what a user can see (beta.18, when pages moved into the Frame): inside a collapsed part a theme switch
|
||||
// re-applies a DataGrid's idle scroll bar, whose arrow glyphs then exist in the switched page only, and the select-all
|
||||
// corner — collapsed, every grid here shows column headers only — kept the old theme's disabled colour.
|
||||
List<string> stale =
|
||||
[
|
||||
.. before.Where(d => made.TryGetValue(d.Path, out DrawnText f) && (d.Shown || f.Shown) && !string.Equals(d.Colour, f.Colour, StringComparison.Ordinal))
|
||||
.Select(d => $"{name}: \"{d.Text}\" is {d.Colour}, made fresh {made[d.Path].Colour} ({d.Path})"),
|
||||
.. before.Where(d => d.Shown && !made.ContainsKey(d.Path)).Select(d => $"{name}: \"{d.Text}\" shows after the switch only ({d.Path})"),
|
||||
.. after.Where(d => d.Shown && !lived.ContainsKey(d.Path)).Select(d => $"{name}: \"{d.Text}\" shows in a fresh one only ({d.Path})"),
|
||||
];
|
||||
return (before.Count, stale.Count <= _staleShownPerSurface ? stale : [.. stale.Take(_staleShownPerSurface), $"{name}: … and {stale.Count - _staleShownPerSurface} more"]);
|
||||
}
|
||||
finally
|
||||
@@ -140,7 +145,12 @@ public sealed partial class PagesLoadTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A surface in a window that is never shown: itself when it is one, otherwise as the window's content.</summary>
|
||||
/// <summary>
|
||||
/// A surface hosted as the App shows it, in a window that is never shown: a window as itself; a page in WPF UI's
|
||||
/// <c>NavigationViewContentPresenter</c>, the shell's Frame — which passes no inherited value into the page, the text
|
||||
/// colour included (beta.18; until then pages sat straight in the window here, and their black titles inherited the
|
||||
/// window's colour in this check only); anything else as the window's content.
|
||||
/// </summary>
|
||||
private static (Window Host, FrameworkElement Root) Hosted(Func<FrameworkElement> build)
|
||||
{
|
||||
FrameworkElement built = build();
|
||||
@@ -149,6 +159,16 @@ public sealed partial class PagesLoadTests
|
||||
return (window, (FrameworkElement)window.Content);
|
||||
}
|
||||
|
||||
if (built is Page page)
|
||||
{
|
||||
var frame = new Wpf.Ui.Controls.NavigationViewContentPresenter();
|
||||
var shell = new Wpf.Ui.Controls.FluentWindow { Content = frame };
|
||||
Lay(frame);
|
||||
_ = frame.Navigate(page);
|
||||
Visuals.Pump();
|
||||
return (shell, frame);
|
||||
}
|
||||
|
||||
// A FluentWindow, as the shell is: its style gives the inherited text colour by theme resource too.
|
||||
var host = new Wpf.Ui.Controls.FluentWindow { Content = built };
|
||||
return (host, built);
|
||||
@@ -156,28 +176,34 @@ public sealed partial class PagesLoadTests
|
||||
|
||||
private static void Lay(FrameworkElement root) => Visuals.Layout(root, 1200, 900);
|
||||
|
||||
/// <summary>Every TextBlock under <paramref name="root"/> in visual-tree order: where it is, what it says, the colour it is drawn in.</summary>
|
||||
private static List<(string Path, string Text, string Colour)> Texts(DependencyObject root)
|
||||
/// <summary>
|
||||
/// Every TextBlock under <paramref name="root"/> in visual-tree order: where it is, what it says, the colour it is drawn
|
||||
/// in, and whether it shows — nothing above it collapsed or hidden.
|
||||
/// </summary>
|
||||
private static List<DrawnText> Texts(DependencyObject root)
|
||||
{
|
||||
var found = new List<(string, string, string)>();
|
||||
Walk(root, root.GetType().Name, found);
|
||||
var found = new List<DrawnText>();
|
||||
Walk(root, root.GetType().Name, shown: true, found);
|
||||
return found;
|
||||
}
|
||||
|
||||
private static void Walk(DependencyObject node, string path, List<(string, string, string)> found)
|
||||
private static void Walk(DependencyObject node, string path, bool shown, List<DrawnText> found)
|
||||
{
|
||||
shown &= node is not UIElement { Visibility: not Visibility.Visible };
|
||||
if (node is TextBlock text)
|
||||
{
|
||||
found.Add((path, text.Text, text.Foreground is SolidColorBrush solid ? solid.Color.ToString(CultureInfo.InvariantCulture) : text.Foreground?.ToString(CultureInfo.InvariantCulture) ?? "null"));
|
||||
found.Add(new DrawnText(path, text.Text, text.Foreground is SolidColorBrush solid ? solid.Color.ToString(CultureInfo.InvariantCulture) : text.Foreground?.ToString(CultureInfo.InvariantCulture) ?? "null", shown));
|
||||
}
|
||||
|
||||
int count = VisualTreeHelper.GetChildrenCount(node);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
DependencyObject child = VisualTreeHelper.GetChild(node, i);
|
||||
Walk(child, string.Create(CultureInfo.InvariantCulture, $"{path}/{child.GetType().Name}[{i}]"), found);
|
||||
Walk(child, string.Create(CultureInfo.InvariantCulture, $"{path}/{child.GetType().Name}[{i}]"), shown, found);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly record struct DrawnText(string Path, string Text, string Colour, bool Shown);
|
||||
|
||||
private static Color Solid(Brush brush) => brush is SolidColorBrush solid ? solid.Color : throw new InvalidOperationException("a text whose foreground is not a solid colour");
|
||||
}
|
||||
@@ -76,14 +76,31 @@ internal static class Visuals
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs <paramref name="work"/> with the App's theme dictionary swapped for <paramref name="theme"/>, and puts Dark back:
|
||||
/// elements made inside take the theme's resources when they are created.
|
||||
/// Windows' default accent. The App derives its accent resources from the system's at each theme switch; the checks
|
||||
/// derive them from this one colour, so a result does not depend on the machine's personalisation.
|
||||
/// </summary>
|
||||
public static readonly Color DefaultAccent = Color.FromRgb(0x00, 0x78, 0xD4);
|
||||
|
||||
/// <summary>
|
||||
/// Runs <paramref name="work"/> under <paramref name="theme"/> the way the App switches (<c>WpfThemeApplier</c> →
|
||||
/// <c>ApplicationThemeManager.Apply(theme, …, updateAccent: true)</c>): the accent resources derived for the theme from
|
||||
/// <see cref="DefaultAccent"/>, then the theme dictionary swapped. Afterwards the dictionary and the application's own
|
||||
/// resources are put back as they were, so no other check inherits this one's theme. Elements made inside take the
|
||||
/// theme's resources when they are created; elements made before it hear the change, as a shown window does.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The accent is not in the theme dictionaries (WPF UI 4.3.0 writes it into <c>Application.Resources</c>), and the
|
||||
/// test application's only accent is <c>Accent.xaml</c>'s default, the dark theme's: before 2026-10-07 a check under
|
||||
/// Light measured a link in the dark theme's light blue on the light window, 1.9:1, a colour the App never shows.
|
||||
/// </remarks>
|
||||
public static T UnderTheme<T>(ApplicationTheme theme, Func<T> work)
|
||||
{
|
||||
System.Collections.ObjectModel.Collection<ResourceDictionary> merged = System.Windows.Application.Current.Resources.MergedDictionaries;
|
||||
ResourceDictionary resources = System.Windows.Application.Current.Resources;
|
||||
System.Collections.ObjectModel.Collection<ResourceDictionary> merged = resources.MergedDictionaries;
|
||||
int index = merged.ToList().FindIndex(static d => d is ThemesDictionary);
|
||||
ResourceDictionary original = merged[index];
|
||||
Dictionary<object, object> own = resources.Keys.Cast<object>().ToDictionary(static k => k, k => resources[k]);
|
||||
ApplicationAccentColorManager.Apply(DefaultAccent, theme);
|
||||
merged[index] = new ThemesDictionary { Theme = theme };
|
||||
try
|
||||
{
|
||||
@@ -92,6 +109,15 @@ internal static class Visuals
|
||||
finally
|
||||
{
|
||||
merged[index] = original;
|
||||
foreach (object added in resources.Keys.Cast<object>().Where(k => !own.ContainsKey(k)).ToList())
|
||||
{
|
||||
resources.Remove(added);
|
||||
}
|
||||
|
||||
foreach ((object key, object value) in own.Where(kv => !ReferenceEquals(resources[kv.Key], kv.Value)))
|
||||
{
|
||||
resources[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ Japanese wait for a human reviewer, never a machine draft ([`docs/09_I18N.md`](.
|
||||
## Colours and theme
|
||||
|
||||
Colours come only from WPF UI's theme brushes, by `DynamicResource` — never a hex value, never `StaticResource` for a
|
||||
theme brush. Muted text uses the App's `SecondaryText` and `TertiaryText` styles (`src/FrameLedger.App/Styles/FrameLedger.xaml`).
|
||||
theme brush. Muted text uses the App's `SecondaryText` and `TertiaryText` styles (`src/FrameLedger.App/Styles/FrameLedger.xaml`),
|
||||
and every page sets the theme's text colour on its root.
|
||||
The chart palettes are the one place a colour is written out, once per theme.
|
||||
|
||||
## The traps of WPF UI 4.3.0
|
||||
@@ -32,6 +33,7 @@ Each of these cost a release; the full list, with the tests that hold each, is
|
||||
[`docs/16_WPFUI_SYNTAX.md`](../docs/16_WPFUI_SYNTAX.md).
|
||||
|
||||
- `ui:TextBlock Appearance=` looks its brush up once: a theme switch leaves the text in the old theme's colour.
|
||||
- A page is shown in a `Frame`, which passes it no text colour: a text that sets none is black, on the dark theme too.
|
||||
- A class handler on `Loaded` does not reach every element: WPF raises Loaded only where a subtree listens for it.
|
||||
- Every page sets `ScrollViewer.CanContentScroll="False"`, or WPF UI wraps it in a scroller that eats the mouse wheel;
|
||||
a scroller inside a dialog is a `ui:PassiveScrollViewer`.
|
||||
@@ -45,4 +47,5 @@ Each of these cost a release; the full list, with the tests that hold each, is
|
||||
|
||||
`tests/FrameLedger.App.Tests` renders every page, window and dialog under the real theme dictionaries on one STA thread
|
||||
(`PagesLoadTests.OnStaAsync`): contrast in both themes, a theme switch while a surface is on screen, scroll bars with the
|
||||
option on in a real window, keyboard and automation names. A rendered check is run red against the unfixed XAML first.
|
||||
option on in a real window, keyboard and automation names. Each surface is hosted as the App hosts it — a page in WPF UI's
|
||||
navigation presenter, not straight in a window. A rendered check is run red against the unfixed XAML first.
|
||||
Reference in new issue
Block a user