From baf3c6bdddfcf0be4ce1e6d7db4733a01ece3c98 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 3 Oct 2026 17:23:33 +0000 Subject: [PATCH] fix(app): every window follows the reading direction; live regions and left-to-right text Windows created after the language was applied (the main window at start, every dialog) now take FlowDirection from the current culture when they load, so an Arabic or Hebrew UI stays mirrored after a restart and in dialogs. Adds LiveRegion.Text (announces status changes to screen readers) and Formatting.LeftToRight (keeps paths, addresses and fingerprints in order inside right-to-left text). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- src/Titano.App/Infrastructure/Formatting.cs | 6 ++++ src/Titano.App/Infrastructure/LiveRegion.cs | 32 +++++++++++++++++++++ src/Titano.App/Infrastructure/UiLanguage.cs | 12 ++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/Titano.App/Infrastructure/LiveRegion.cs diff --git a/src/Titano.App/Infrastructure/Formatting.cs b/src/Titano.App/Infrastructure/Formatting.cs index 18c48b23..60fd23b0 100644 --- a/src/Titano.App/Infrastructure/Formatting.cs +++ b/src/Titano.App/Infrastructure/Formatting.cs @@ -56,4 +56,10 @@ public static class Formatting /// Camera wall-clock date in the culture's short format. public static string Date(DateTime wallClock) => wallClock.ToString("d", Loc.Culture); + + /// + /// A path, address or fingerprint kept left to right inside right-to-left text (a Unicode left-to-right embedding), + /// so its separators and digits stay in place; it reads unchanged in left-to-right languages. + /// + public static string LeftToRight(string text) => "‪" + text + "‬"; } diff --git a/src/Titano.App/Infrastructure/LiveRegion.cs b/src/Titano.App/Infrastructure/LiveRegion.cs new file mode 100644 index 00000000..3bfdf6e2 --- /dev/null +++ b/src/Titano.App/Infrastructure/LiveRegion.cs @@ -0,0 +1,32 @@ +using System.Windows; +using System.Windows.Automation; +using System.Windows.Automation.Peers; +using System.Windows.Threading; + +namespace Titano.App.Infrastructure; + +/// +/// A status line screen readers announce when it changes (a live region): LiveRegion.Text becomes the element's +/// accessible name and every later change raises . The element's +/// (Polite, or Assertive for errors) must be set as well. +/// +public static class LiveRegion +{ + public static readonly DependencyProperty TextProperty = DependencyProperty.RegisterAttached( + "Text", typeof(string), typeof(LiveRegion), new PropertyMetadata(null, OnTextChanged)); + + public static string? GetText(DependencyObject element) => (string?)element.GetValue(TextProperty); + + public static void SetText(DependencyObject element, string? value) => element.SetValue(TextProperty, value); + + private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is not FrameworkElement element) return; + AutomationProperties.SetName(element, (string?)e.NewValue ?? string.Empty); + // The first value arrives with the screen: only what changes while it is shown is announced, once layout has shown + // it (a status that appears with its text is still collapsed when the text arrives). + if (!element.IsLoaded || e.NewValue is null || !AutomationPeer.ListenerExists(AutomationEvents.LiveRegionChanged)) return; + element.Dispatcher.InvokeAsync(() => UIElementAutomationPeer.CreatePeerForElement(element)?.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged), + DispatcherPriority.Background); + } +} diff --git a/src/Titano.App/Infrastructure/UiLanguage.cs b/src/Titano.App/Infrastructure/UiLanguage.cs index e2a5f783..66ba0b02 100644 --- a/src/Titano.App/Infrastructure/UiLanguage.cs +++ b/src/Titano.App/Infrastructure/UiLanguage.cs @@ -7,6 +7,15 @@ namespace Titano.App.Infrastructure; /// Switches the UI language at run time without restart (BRIEF §16), mirroring right-to-left languages. public static class UiLanguage { + static UiLanguage() + { + // Windows created later (the main window at start, every dialog) take the reading direction when they load. + EventManager.RegisterClassHandler(typeof(Window), FrameworkElement.LoadedEvent, new RoutedEventHandler((sender, _) => ((Window)sender).FlowDirection = Direction)); + } + + /// The reading direction of the current language. + public static FlowDirection Direction => Loc.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; + /// Applies (or the OS language when null) and returns the culture in use. public static CultureInfo Apply(string? code) { @@ -25,8 +34,7 @@ public static class UiLanguage Loc.SetCulture(culture); if (Application.Current is { } app) { - foreach (Window window in app.Windows) - window.FlowDirection = Loc.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; + foreach (Window window in app.Windows) window.FlowDirection = Direction; } return culture; }