fix(ui): text and password boxes pad their text once; shared password error state

- The text box hands its Padding to the content host itself; the template no longer adds it again, so
  typed text starts where the placeholder does (12 px, 8 px after a leading icon). Same for the password box.
- ui:Field.Error marks an input without a validating binding (a password box) with the error border and
  makes the sentence its help text; the Uploader and the login dialog use it instead of drawing their own.
- The brand mark keeps its orientation by itself; the local left-to-right settings are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-06 08:10:36 +00:00
1 parent 70dc18787a
commit a7f5f83e04
8 files changed
+52 -30

No files matched your search

+23 -1
View File
@@ -2,7 +2,10 @@ using System.Windows;
namespace Titano.Ui.Controls;
/// <summary>Attached field helpers: placeholder text and an inline leading icon for text inputs.</summary>
/// <summary>
/// Attached field helpers: placeholder text and an inline leading icon for text inputs, and the error of an input that
/// has no validating binding (a password box): the error border, with the message as help text for screen readers.
/// </summary>
public static class Field
{
public static readonly DependencyProperty PlaceholderProperty = DependencyProperty.RegisterAttached(
@@ -11,6 +14,16 @@ public static class Field
public static readonly DependencyProperty GlyphProperty = DependencyProperty.RegisterAttached(
"Glyph", typeof(IconData), typeof(Field), new FrameworkPropertyMetadata(null));
/// <summary>One sentence saying what is wrong with the value; null when it is fine.</summary>
public static readonly DependencyProperty ErrorProperty = DependencyProperty.RegisterAttached(
"Error", typeof(string), typeof(Field), new FrameworkPropertyMetadata(null, OnErrorChanged));
private static readonly DependencyPropertyKey HasErrorKey = DependencyProperty.RegisterAttachedReadOnly(
"HasError", typeof(bool), typeof(Field), new FrameworkPropertyMetadata(false));
/// <summary>True while <see cref="ErrorProperty"/> holds a message; the input templates trigger on it.</summary>
public static readonly DependencyProperty HasErrorProperty = HasErrorKey.DependencyProperty;
public static string? GetPlaceholder(DependencyObject d) => (string?)d.GetValue(PlaceholderProperty);
public static void SetPlaceholder(DependencyObject d, string? value) => d.SetValue(PlaceholderProperty, value);
@@ -18,6 +31,15 @@ public static class Field
public static IconData? GetGlyph(DependencyObject d) => (IconData?)d.GetValue(GlyphProperty);
public static void SetGlyph(DependencyObject d, IconData? value) => d.SetValue(GlyphProperty, value);
public static string? GetError(DependencyObject d) => (string?)d.GetValue(ErrorProperty);
public static void SetError(DependencyObject d, string? value) => d.SetValue(ErrorProperty, value);
public static bool GetHasError(DependencyObject d) => (bool)d.GetValue(HasErrorProperty);
private static void OnErrorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
d.SetValue(HasErrorKey, !string.IsNullOrEmpty((string?)e.NewValue));
}
/// <summary>Attached glyph for buttons: renders an <see cref="IconData"/> before (or instead of) the content.</summary>
+18 -10
View File
@@ -223,24 +223,26 @@
<Setter Property="SelectionOpacity" Value="0.35" />
<Setter Property="Template">
<Setter.Value>
<!-- The text box hands its Padding to the content host itself, so the template applies it nowhere else: the
placeholder takes it as its own padding (plus the 2 px the text view adds) and the leading icon sits at its
left edge; with an icon, text and placeholder start 8 px after it. -->
<ControlTemplate TargetType="TextBox">
<Border x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{StaticResource Radius.Control}" SnapsToDevicePixels="True">
<Grid Margin="{TemplateBinding Padding}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ui:Icon x:Name="Glyph" Glyph="{TemplateBinding ui:Field.Glyph}" Foreground="{DynamicResource Brush.TextFaint}" Margin="0,0,8,0" VerticalAlignment="Center" />
<TextBlock x:Name="Placeholder" Grid.Column="1" Text="{TemplateBinding ui:Field.Placeholder}" Foreground="{DynamicResource Brush.TextFaint}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Visibility="Collapsed" IsHitTestVisible="False" TextTrimming="CharacterEllipsis" Margin="2,0,0,0" />
<ScrollViewer x:Name="PART_ContentHost" Grid.Column="1" Focusable="False" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
<Grid>
<ui:Icon x:Name="Glyph" Glyph="{TemplateBinding ui:Field.Glyph}" Foreground="{DynamicResource Brush.TextFaint}" HorizontalAlignment="Left"
Margin="{TemplateBinding Padding}" />
<TextBlock x:Name="Placeholder" Text="{TemplateBinding ui:Field.Placeholder}" Foreground="{DynamicResource Brush.TextFaint}" Padding="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Visibility="Collapsed" IsHitTestVisible="False" TextTrimming="CharacterEllipsis" Margin="24,0,0,0" />
<ScrollViewer x:Name="PART_ContentHost" Focusable="False" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="22,0,0,0"
HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="ui:Field.Glyph" Value="{x:Null}">
<Setter TargetName="Glyph" Property="Visibility" Value="Collapsed" />
<Setter TargetName="Placeholder" Property="Margin" Value="2,0,0,0" />
<Setter TargetName="PART_ContentHost" Property="Margin" Value="0" />
</Trigger>
<Trigger Property="Text" Value="">
<Setter TargetName="Placeholder" Property="Visibility" Value="Visible" />
@@ -282,10 +284,11 @@
<Setter Property="SelectionBrush" Value="{DynamicResource Brush.Accent}" />
<Setter Property="Template">
<Setter.Value>
<!-- As for TextBox, the password box hands its Padding to the content host itself. -->
<ControlTemplate TargetType="PasswordBox">
<Border x:Name="Bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{StaticResource Radius.Control}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Margin="{TemplateBinding Padding}" VerticalAlignment="Center" Focusable="False"
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center" Focusable="False"
HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" />
</Border>
<ControlTemplate.Triggers>
@@ -295,6 +298,11 @@
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Brush.Accent}" />
</Trigger>
<!-- A password has no binding to validate: the owner sets ui:Field.Error (DESIGN §4 error state, as TextBox). -->
<Trigger Property="ui:Field.HasError" Value="True">
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Brush.Error}" />
<Setter Property="AutomationProperties.HelpText" Value="{Binding (ui:Field.Error), RelativeSource={RelativeSource Self}}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.4" />
</Trigger>