Skip to content

Commit

Permalink
ProgressBar: Update indicator size when Padding changes. (#2418)
Browse files Browse the repository at this point in the history
* ProgressBar: Update indicator size when Padding changes.

* Update DP changed handler name.

Co-authored-by: Stephen Peters <stpete@microsoft.com>
  • Loading branch information
carldebilly and StephenLPeters committed Jun 2, 2020
1 parent 0986935 commit 3e33555
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions dev/ProgressBar/ProgressBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ ProgressBar::ProgressBar()

// NOTE: This is necessary only because Value isn't one of OUR properties, it's implemented in RangeBase.
// If it was one of ProgressBar's properties, defined in the IDL, you'd do it differently (see IsIndeterminate).
RegisterPropertyChangedCallback(winrt::RangeBase::ValueProperty(), { this, &ProgressBar::OnRangeBasePropertyChanged });
RegisterPropertyChangedCallback(winrt::RangeBase::MinimumProperty(), { this, &ProgressBar::OnRangeBasePropertyChanged });
RegisterPropertyChangedCallback(winrt::RangeBase::MaximumProperty(), { this, &ProgressBar::OnRangeBasePropertyChanged });
RegisterPropertyChangedCallback(winrt::RangeBase::ValueProperty(), { this, &ProgressBar::OnIndicatorWidthComponentChanged });
RegisterPropertyChangedCallback(winrt::RangeBase::MinimumProperty(), { this, &ProgressBar::OnIndicatorWidthComponentChanged });
RegisterPropertyChangedCallback(winrt::RangeBase::MaximumProperty(), { this, &ProgressBar::OnIndicatorWidthComponentChanged });
RegisterPropertyChangedCallback(winrt::Control::PaddingProperty(), { this, &ProgressBar::OnIndicatorWidthComponentChanged });

SetValue(s_TemplateSettingsProperty, winrt::make<::ProgressBarTemplateSettings>());
}
Expand Down Expand Up @@ -52,7 +53,7 @@ void ProgressBar::OnSizeChanged(const winrt::IInspectable&, const winrt::IInspec
UpdateWidthBasedTemplateSettings();
}

void ProgressBar::OnRangeBasePropertyChanged(const winrt::DependencyObject& sender, const winrt::DependencyProperty& args)
void ProgressBar::OnIndicatorWidthComponentChanged(const winrt::DependencyObject& sender, const winrt::DependencyProperty& args)
{
// NOTE: This hits when the Value property changes, because we called RegisterPropertyChangedCallback.
SetProgressBarIndicatorWidth();
Expand All @@ -62,7 +63,7 @@ void ProgressBar::OnIsIndeterminatePropertyChanged(const winrt::DependencyProper
{
// NOTE: This hits when IsIndeterminate changes because we set MUX_PROPERTY_CHANGED_CALLBACK to true in the idl.
SetProgressBarIndicatorWidth();
UpdateStates();
UpdateStates();
}

void ProgressBar::OnShowPausedPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args)
Expand Down Expand Up @@ -120,7 +121,7 @@ void ProgressBar::SetProgressBarIndicatorWidth()

// Adds "Updating" state in between to trigger RepositionThemeAnimation Visual Transition
// in ProgressBar.xaml when reverting back to previous state
winrt::VisualStateManager::GoToState(*this, s_UpdatingStateName, true);
winrt::VisualStateManager::GoToState(*this, s_UpdatingStateName, true);

if (IsIndeterminate())
{
Expand Down Expand Up @@ -149,7 +150,7 @@ void ProgressBar::SetProgressBarIndicatorWidth()
{
determinateProgressBarIndicator.Width(0); // Error
}

UpdateStates(); // Reverts back to previous state
}
}
Expand Down
2 changes: 1 addition & 1 deletion dev/ProgressBar/ProgressBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProgressBar :
void OnShowPausedPropertyChanged(const winrt::DependencyPropertyChangedEventArgs& args);

private:
void OnRangeBasePropertyChanged(const winrt::DependencyObject& sender, const winrt::DependencyProperty& args);
void OnIndicatorWidthComponentChanged(const winrt::DependencyObject& sender, const winrt::DependencyProperty& args);

void SetProgressBarIndicatorWidth();
void UpdateStates();
Expand Down

0 comments on commit 3e33555

Please sign in to comment.