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:
@@ -243,7 +243,19 @@
|
|||||||
<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,
|
||||||
|
pas seulement clic sur la flèche. Le ContentPresenter par-dessus
|
||||||
|
est en IsHitTestVisible=False pour ne pas voler le clic. -->
|
||||||
|
<ToggleButton x:Name="ToggleBtn"
|
||||||
|
Background="{TemplateBinding Background}"
|
||||||
|
BorderBrush="{TemplateBinding BorderBrush}"
|
||||||
|
BorderThickness="{TemplateBinding BorderThickness}"
|
||||||
|
Cursor="Hand"
|
||||||
|
Focusable="False"
|
||||||
|
IsChecked="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
|
||||||
|
<ToggleButton.Template>
|
||||||
|
<ControlTemplate TargetType="ToggleButton">
|
||||||
|
<Border x:Name="Bd"
|
||||||
Background="{TemplateBinding Background}"
|
Background="{TemplateBinding Background}"
|
||||||
BorderBrush="{TemplateBinding BorderBrush}"
|
BorderBrush="{TemplateBinding BorderBrush}"
|
||||||
BorderThickness="{TemplateBinding BorderThickness}"
|
BorderThickness="{TemplateBinding BorderThickness}"
|
||||||
@@ -253,19 +265,27 @@
|
|||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
<ColumnDefinition Width="28" />
|
<ColumnDefinition Width="28" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<ContentPresenter Grid.Column="0"
|
<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}"
|
Content="{TemplateBinding SelectionBoxItem}"
|
||||||
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
|
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
|
||||||
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
|
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
|
||||||
Margin="{TemplateBinding Padding}"
|
Margin="{TemplateBinding Padding}"
|
||||||
VerticalAlignment="Center"
|
HorizontalAlignment="Left" VerticalAlignment="Center"
|
||||||
HorizontalAlignment="Stretch"
|
|
||||||
TextElement.Foreground="{TemplateBinding Foreground}" />
|
TextElement.Foreground="{TemplateBinding Foreground}" />
|
||||||
<ToggleButton Grid.Column="1"
|
|
||||||
Style="{StaticResource ComboBoxToggleButton}"
|
|
||||||
IsChecked="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" />
|
|
||||||
</Grid>
|
|
||||||
</Border>
|
|
||||||
<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>
|
||||||
|
|||||||
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user