microsoft/microsoft-ui-xaml

ToggleSwitch control internally sets a `MinWidth` to 154, which is way larger than its default width

Open

#3,652 opened on 2020年11月19日

GitHub で見る
 (16 comments) (11 reactions) (0 assignees)C# (5,815 stars) (659 forks)batch import
area-ToggleSwitchbughelp wantedteam-Controls

説明

Describe the bug The ToggleSwitch control template sets the MinWidth of one of its internal Grid to 154, through the following resource:

<x:Double x:Key="ToggleSwitchThemeMinWidth">154</x:Double>

Because of that, if you put a ToggleSwitch control in a column of a Grid having its ColumnDefinition width set to Auto, the column won't adjust to the size of the ToggleSwitch by default. I tried to redefine ToggleSwitchThemeMinWidth resource in many places of my application to try to override it without success.

Note that this issue can be mitigated with one of the following workarounds, but this is not ideal:

  • Set the Width property of the ToggleSwitch control to a fixed value
  • Retemplate the whole ToggleSwitch

Steps to reproduce the bug For instance, put the following XAML code in a sample page:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>

    <TextBlock Text="Here is a TextBlock" />
    <ToggleSwitch Grid.Column="1" />
</Grid>

Expected behavior I would expect the ToggleSwitch control to be aligned on the right of the grid.

Screenshots Instead, there is a lot of wasted space on the right, as you can see in the following screenshot: image

Version Info

NuGet package version: [Microsoft.UI.Xaml 2.4.3]

Windows app type:

UWP Win32
Yes
Windows 10 version Saw the problem?
Insider Build (xxxxx)
20H2 (19042) Yes
May 2020 Update (19041)
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Additional context

コントリビューターガイド