question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
mdtaukcommented, Jul 30, 2023

I think this is still an Issue.

0reactions
yki5000commented, Aug 17, 2023

Still an issue in 1.3.230724000.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ToggleSwitch Class (Windows.UI.Xaml.Controls)
Identifies the IsOn dependency property. Gets or sets a value that determines whether the RightTapped event can originate from that element.
Read more >
windows 8 - Toggleswitch size in xaml
Open Blend and right-click the toggleswitch in the designer. Pick the Edit Template\Edit a ... Here is the resulting XAML from the edit....
Read more >
Untitled
Wpf minwidth default WebMar 3, 2011 · However, I realised that all I need to do is set the Width and Height of...
Read more >
Perspective toggle switch size - Ignition Early Access
The toggle switch appears to be a fixed size - adjusting the height and width of the component seems to just add more...
Read more >
PeopleTools 8.56: Fluid User Interface Developer's Guide
The Fluid User Interface design approach gives developers just this type of control over the user experience. When a larger screen size is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found