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 throws System.ArgumentException if Padding is set #17393

Closed
pavelovcharov opened this issue Oct 31, 2024 · 1 comment · Fixed by #17816
Closed

ProgressBar throws System.ArgumentException if Padding is set #17393

pavelovcharov opened this issue Oct 31, 2024 · 1 comment · Fixed by #17816
Labels
bug help-wanted A contribution from the community would be most welcome.

Comments

@pavelovcharov
Copy link
Contributor

pavelovcharov commented Oct 31, 2024

Describe the bug

In Avalonia 11.2.0 ProgressBar throws System.ArgumentException if you set the Padding property

System.ArgumentException: -0,2 is not a valid value for 'Width.
   at Avalonia.PropertyStore.ValueStore.SetValue[T](StyledProperty`1 property, T value, BindingPriority priority)
   at Avalonia.AvaloniaObject.SetValue[T](StyledProperty`1 property, T value, BindingPriority priority)
   at Avalonia.Layout.Layoutable.set_Width(Double value)
   at Avalonia.Controls.ProgressBar.UpdateIndicator()
   at Avalonia.Controls.ProgressBar.OnApplyTemplate(TemplateAppliedEventArgs e)
   at Avalonia.Controls.Primitives.TemplatedControl.ApplyTemplate()
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.LayoutHelper.MeasureChild(Layoutable control, Size availableSize, Thickness padding, Thickness borderThickness)
   at Avalonia.Controls.Presenters.ContentPresenter.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.LayoutHelper.MeasureChild(Layoutable control, Size availableSize, Thickness padding)
   at Avalonia.Controls.Decorator.MeasureOverride(Size availableSize)
   at Avalonia.Controls.Primitives.VisualLayerManager.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureOverride(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.Layoutable.MeasureOverride(Size availableSize)
   at Avalonia.Controls.Window.MeasureOverride(Size availableSize)
   at Avalonia.Controls.WindowBase.MeasureCore(Size availableSize)
   at Avalonia.Layout.Layoutable.Measure(Size availableSize)
   at Avalonia.Layout.LayoutManager.Measure(Layoutable control)
   at Avalonia.Layout.LayoutManager.ExecuteInitialLayoutPass()
   at Avalonia.Controls.Window.ShowCore(Window owner)
   at Avalonia.Controls.Window.Show()
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.ShowMainWindow()
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.StartCore(String[] args)
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args)
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, Action`1 lifetimeBuilder)
   at AvaloniaApplication4.Program.Main(String[] args) in E:\work\tests\AvaloniaApplication4\AvaloniaApplication4\Program.cs:line 12

To Reproduce

Add a ProgressBar control to your XAML markup

 <ProgressBar Padding="1" Value="10"></ProgressBar>

Expected behavior

No exception should be thrown

Avalonia version

11.2.0

OS

No response

Additional context

https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/ProgressBar.cs#L348

Looks like the UpdateIndicator method should not be called in the OnApplyTemplate method, because the ProgressBar's visual tree is not measured yet

@timunie timunie added the help-wanted A contribution from the community would be most welcome. label Nov 1, 2024
@timunie
Copy link
Contributor

timunie commented Nov 1, 2024

@pavelovcharov maybe you are right about that finding. If you have an idea how to fix it feel free to open a PR. Mind that template can change in theory while control is already loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted A contribution from the community would be most welcome.
Projects
None yet
2 participants