ComboBox fixes: clickable center + display the option name, not the record

Two issues with the language picker after the dark restyling:

1. Click on the center of the ComboBox was a no-op — only the arrow
   triggered the dropdown. The previous template had a separate
   ToggleButton in column 1 covering only the arrow region. New
   template wraps the entire body in a single ToggleButton (with its
   own template carrying the border + arrow), and the ContentPresenter
   for the selected text floats on top with IsHitTestVisible="False"
   so clicks pass through to the toggle.

2. Selected item showed "LanguageOption { Code = auto, Name = ... }"
   instead of just the name. C# record types stringify with property
   names by default. Override LanguageOption.ToString() to return Name
   so the SelectionBox falls back to a clean label even though
   DisplayMemberPath="Name" is set on the dropdown items.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-02 13:44:00 +02:00
parent 5d0284f1db
commit b9ce591d22
2 changed files with 49 additions and 32 deletions

View File

@@ -243,29 +243,49 @@
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="ComboBox"> <ControlTemplate TargetType="ComboBox">
<Grid> <Grid>
<Border x:Name="Border" <!-- ToggleButton couvre TOUT le combo : clic au centre ouvre le dropdown,
Background="{TemplateBinding Background}" pas seulement clic sur la flèche. Le ContentPresenter par-dessus
BorderBrush="{TemplateBinding BorderBrush}" est en IsHitTestVisible=False pour ne pas voler le clic. -->
BorderThickness="{TemplateBinding BorderThickness}" <ToggleButton x:Name="ToggleBtn"
CornerRadius="4"> Background="{TemplateBinding Background}"
<Grid> BorderBrush="{TemplateBinding BorderBrush}"
<Grid.ColumnDefinitions> BorderThickness="{TemplateBinding BorderThickness}"
<ColumnDefinition Width="*" /> Cursor="Hand"
<ColumnDefinition Width="28" /> Focusable="False"
</Grid.ColumnDefinitions> IsChecked="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
<ContentPresenter Grid.Column="0" <ToggleButton.Template>
Content="{TemplateBinding SelectionBoxItem}" <ControlTemplate TargetType="ToggleButton">
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" <Border x:Name="Bd"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" Background="{TemplateBinding Background}"
Margin="{TemplateBinding Padding}" BorderBrush="{TemplateBinding BorderBrush}"
VerticalAlignment="Center" BorderThickness="{TemplateBinding BorderThickness}"
HorizontalAlignment="Stretch" CornerRadius="4">
TextElement.Foreground="{TemplateBinding Foreground}" /> <Grid>
<ToggleButton Grid.Column="1" <Grid.ColumnDefinitions>
Style="{StaticResource ComboBoxToggleButton}" <ColumnDefinition Width="*" />
IsChecked="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" /> <ColumnDefinition Width="28" />
</Grid> </Grid.ColumnDefinitions>
</Border> <Path Grid.Column="1"
HorizontalAlignment="Center" VerticalAlignment="Center"
Data="M 0,0 L 8,0 L 4,5 Z"
Fill="{StaticResource Brush.Text.Secondary}" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource Brush.Accent}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
<ContentPresenter IsHitTestVisible="False"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="Left" VerticalAlignment="Center"
TextElement.Foreground="{TemplateBinding Foreground}" />
<Popup x:Name="PART_Popup" <Popup x:Name="PART_Popup"
Placement="Bottom" Placement="Bottom"
IsOpen="{TemplateBinding IsDropDownOpen}" IsOpen="{TemplateBinding IsDropDownOpen}"
@@ -284,14 +304,6 @@
</Border> </Border>
</Popup> </Popup>
</Grid> </Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource Brush.Accent}" />
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource Brush.Accent}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>

View File

@@ -13,7 +13,12 @@ using PSLauncher.Models;
namespace PSLauncher.App.ViewModels; namespace PSLauncher.App.ViewModels;
public sealed record LanguageOption(string Code, string Name); public sealed record LanguageOption(string Code, string Name)
{
// Override pour que la SelectionBox d'un ComboBox affiche le libellé clair
// (sinon WPF affiche la forme record "LanguageOption { Code = ..., Name = ... }").
public override string ToString() => Name;
}
public sealed partial class SettingsViewModel : ObservableObject public sealed partial class SettingsViewModel : ObservableObject
{ {