Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProgressBar track height is not overridable #9010

Closed
AndrewKeepCoding opened this issue Oct 24, 2023 · 4 comments
Closed

ProgressBar track height is not overridable #9010

AndrewKeepCoding opened this issue Oct 24, 2023 · 4 comments
Labels
area-Progress ProgressBar, ProgressRing bug Something isn't working team-Controls Issue for the Controls team

Comments

@AndrewKeepCoding
Copy link
Contributor

Describe the bug

The ProgressBar track height is not overridable.
For example, the code below should render a ProgresBar with a track that fills (or almost fills) the green border,

<Grid>
    <Grid.Resources>
        <x:Double x:Key="ProgressBarTrackHeight">50</x:Double>
    </Grid.Resources>
    <ProgressBar
        Height="50"
        BorderBrush="LightGreen"
        BorderThickness="1"
        Maximum="100"
        Value="70" />
</Grid>

but renders this instead:
image

Steps to reproduce the bug

Use the code above.

Expected behavior

ProgressBarTrackHeight should be applied to the track height.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.4.2: 1.4.231008000

Windows version

No response

Additional context

This issue was supposed to be fixed by #6061.

@AndrewKeepCoding AndrewKeepCoding added the bug Something isn't working label Oct 24, 2023
@AndrewKeepCoding
Copy link
Contributor Author

AndrewKeepCoding commented Oct 24, 2023

For those who needs a quick workaround until this issue gets fixed, something like this seems to work so far:

public class CustomProgressBar : ProgressBar
{
    private long _heightPropertyChangedCallBackToken;

    public CustomProgressBar () : base()
    {
        Loaded += OnLoaded;
        Unloaded += OnUnloaded;
    }

    private void OnLoaded(object sender, RoutedEventArgs e)
    {
        _heightPropertyChangedCallBackToken = RegisterPropertyChangedCallback(HeightProperty, OnHeightPropertyChanged);
        ApplyHeight();
    }

    private void OnUnloaded(object sender, RoutedEventArgs e)
    {
        UnregisterPropertyChangedCallback(HeightProperty, _heightPropertyChangedCallBackToken);
    }

    private void ApplyHeight()
    {
        // FindDescendants() is from the CommunityToolkit.WinUI.Extensions NuGet package.
        foreach (FrameworkElement element in this.FindDescendants()
            .OfType<FrameworkElement>()
            .Where(x => x is Grid or Rectangle))
        {
            element.Height = Height;
        }
    }

    private void OnHeightPropertyChanged(DependencyObject sender, DependencyProperty dp)
    {
        ApplyHeight();
    }
}

@castorix
Copy link

castorix commented Oct 24, 2023

If I add MinHeight ="50", I get (with 1.4.230822000 version) :

image

@AndrewKeepCoding
Copy link
Contributor Author

AndrewKeepCoding commented Oct 24, 2023

That's way simple if you won't change the Height dynamically.

So, we can do:

<Grid>
    <Grid.Resources>
        <x:Double x:Key="ProgressBarTrackHeight">50</x:Double>
    </Grid.Resources>
    <ProgressBar
        MinHeight="{StaticResource ProgressBarTrackHeight}"
        Maximum="100"
        Value="70" />
</Grid>

Thanks!

@bpulliam bpulliam added area-Progress ProgressBar, ProgressRing team-Controls Issue for the Controls team labels Oct 26, 2023
@gegao18
Copy link

gegao18 commented Oct 31, 2023

Thanks for reporting this. Closing issue now that there's a MinHeight workaround.

@gegao18 gegao18 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 31, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jul 22, 2024
@codendone codendone removed the needs-triage Issue needs to be triaged by the area owners label Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Progress ProgressBar, ProgressRing bug Something isn't working team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

5 participants