diff --git a/dev/AnimatedIcon/AnimatedIcon.cpp b/dev/AnimatedIcon/AnimatedIcon.cpp index 247bae88c6..40e2b2087e 100644 --- a/dev/AnimatedIcon/AnimatedIcon.cpp +++ b/dev/AnimatedIcon/AnimatedIcon.cpp @@ -51,10 +51,8 @@ void AnimatedIcon::OnApplyTemplate() { winrt::ElementCompositionPreview::SetElementChildVisual(panel, visual.RootVisual()); } - if (auto const source = Source()) - { - TrySetForegroundProperty(source); - } + + TrySetForegroundProperty(); } } @@ -515,17 +513,33 @@ void AnimatedIcon::SetRootPanelChildToFallbackIcon() void AnimatedIcon::OnForegroundPropertyChanged(const winrt::DependencyObject& sender, const winrt::DependencyProperty& args) { - TrySetForegroundProperty(Source()); + m_foregroundColorPropertyChangedRevoker.revoke(); + if (auto const foregroundSolidColorBrush = Foreground().try_as()) + { + m_foregroundColorPropertyChangedRevoker = RegisterPropertyChanged(foregroundSolidColorBrush, winrt::SolidColorBrush::ColorProperty(), { this, &AnimatedIcon::OnForegroundBrushColorPropertyChanged }); + TrySetForegroundProperty(foregroundSolidColorBrush.Color()); + } +} + +void AnimatedIcon::OnForegroundBrushColorPropertyChanged(const winrt::DependencyObject& sender, const winrt::DependencyProperty& args) +{ + TrySetForegroundProperty(sender.GetValue(args).as()); } void AnimatedIcon::TrySetForegroundProperty(winrt::IAnimatedVisualSource2 const& source) { - if (source) + if (auto const foregroundSolidColorBrush = Foreground().try_as()) { - if (auto const ForegroundSolidColorBrush = Foreground().try_as()) - { - source.SetColorProperty(s_foregroundPropertyName, ForegroundSolidColorBrush.Color()); - } + TrySetForegroundProperty(foregroundSolidColorBrush.Color(), source); + } +} + +void AnimatedIcon::TrySetForegroundProperty(winrt::Color color, winrt::IAnimatedVisualSource2 const& source) +{ + auto const localSource = source ? source : Source(); + if (localSource) + { + localSource.SetColorProperty(s_foregroundPropertyName, color); } } diff --git a/dev/AnimatedIcon/AnimatedIcon.h b/dev/AnimatedIcon/AnimatedIcon.h index b2303e2ee0..ff5a3ed86c 100644 --- a/dev/AnimatedIcon/AnimatedIcon.h +++ b/dev/AnimatedIcon/AnimatedIcon.h @@ -50,9 +50,11 @@ class AnimatedIcon : void TransitionAndUpdateStates(const winrt::hstring& fromState, const winrt::hstring& toState, float playbackMultiplier = 1.0f); void TransitionStates(const winrt::hstring& fromState, const winrt::hstring& toState, float playtbackMultiplier = 1.0f); void PlaySegment(float from, float to, float playbackMultiplier = 1.0f); - void TrySetForegroundProperty(winrt::IAnimatedVisualSource2 const& source); + void TrySetForegroundProperty(winrt::Color color, winrt::IAnimatedVisualSource2 const& source = nullptr); + void TrySetForegroundProperty(winrt::IAnimatedVisualSource2 const& source = nullptr); void OnAnimationCompleted(winrt::IInspectable const&, winrt::CompositionBatchCompletedEventArgs const&); void OnForegroundPropertyChanged(const winrt::DependencyObject& sender, const winrt::DependencyProperty& args); + void OnForegroundBrushColorPropertyChanged(const winrt::DependencyObject& sender, const winrt::DependencyProperty& args); void SetRootPanelChildToFallbackIcon(); tracker_ref m_animatedVisual{ this }; @@ -78,6 +80,7 @@ class AnimatedIcon : ScopedBatchCompleted_revoker m_batchCompletedRevoker{ }; PropertyChanged_revoker m_ancestorStatePropertyChangedRevoker{}; winrt::FrameworkElement::LayoutUpdated_revoker m_layoutUpdatedRevoker{}; + PropertyChanged_revoker m_foregroundColorPropertyChangedRevoker{}; winrt::AnimatedIconAnimationQueueBehavior m_queueBehavior{ winrt::AnimatedIconAnimationQueueBehavior::SpeedUpQueueOne }; }; diff --git a/dev/AnimatedIcon/TestUI/AnimatedIconPage.xaml b/dev/AnimatedIcon/TestUI/AnimatedIconPage.xaml index 962d7c933c..2b8747b696 100644 --- a/dev/AnimatedIcon/TestUI/AnimatedIconPage.xaml +++ b/dev/AnimatedIcon/TestUI/AnimatedIconPage.xaml @@ -15,8 +15,8 @@ xmlns:myAnimatedvisuals="using:AnimatedVisuals" mc:Ignorable="d"> - - + + #80808080 + + @@ -145,17 +147,32 @@ + + - + + + - + @@ -173,7 +190,7 @@ - + @@ -191,7 +208,7 @@ - + @@ -212,7 +229,7 @@ - + @@ -230,7 +247,7 @@ - + @@ -248,7 +265,7 @@ - + @@ -269,7 +286,7 @@ - + @@ -287,7 +304,7 @@ - + @@ -305,7 +322,7 @@ - + @@ -326,7 +343,7 @@ - + @@ -341,7 +358,7 @@ - + @@ -356,7 +373,7 @@ - + @@ -374,7 +391,7 @@ - + @@ -389,7 +406,7 @@ - + @@ -404,7 +421,7 @@ - + @@ -422,7 +439,7 @@ - + @@ -439,7 +456,7 @@ - + @@ -456,7 +473,7 @@ - + @@ -476,7 +493,7 @@ - + @@ -491,7 +508,7 @@ - + @@ -506,7 +523,7 @@ - + diff --git a/dev/AnimatedIcon/TestUI/AnimatedIcon_TestUI.projitems b/dev/AnimatedIcon/TestUI/AnimatedIcon_TestUI.projitems index 8011a3996b..47125870a6 100644 --- a/dev/AnimatedIcon/TestUI/AnimatedIcon_TestUI.projitems +++ b/dev/AnimatedIcon/TestUI/AnimatedIcon_TestUI.projitems @@ -21,6 +21,7 @@ AnimatedIconPage.xaml + diff --git a/dev/AnimatedIcon/TestUI/ColorToSolidColorBrushConverter.cs b/dev/AnimatedIcon/TestUI/ColorToSolidColorBrushConverter.cs new file mode 100644 index 0000000000..8250b441c6 --- /dev/null +++ b/dev/AnimatedIcon/TestUI/ColorToSolidColorBrushConverter.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Windows.UI; +using Windows.UI.Xaml.Data; +using Windows.UI.Xaml.Media; + +namespace MUXControlsTestApp +{ + class ColorToSolidColorBrushConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, string language) + { + return new SolidColorBrush((Color)value); + } + + public object ConvertBack(object value, Type targetType, object parameter, string language) + { + return ((SolidColorBrush)value).Color; + } + } +}