From 8ba7234550271aa178cb53077afdbdc9a3c9c66b Mon Sep 17 00:00:00 2001 From: Rudy Huyn Date: Tue, 5 Nov 2019 16:51:36 -0800 Subject: [PATCH] Fix the right arrow button of CalculationResult not disappearing in some cases (#736) --- src/Calculator/Controls/CalculationResult.cpp | 12 ++++++++++++ src/Calculator/Controls/CalculationResult.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/Calculator/Controls/CalculationResult.cpp b/src/Calculator/Controls/CalculationResult.cpp index 2c969c4..c0b7a5b 100644 --- a/src/Calculator/Controls/CalculationResult.cpp +++ b/src/Calculator/Controls/CalculationResult.cpp @@ -87,6 +87,12 @@ void CalculationResult::OnApplyTemplate() } } + if (m_textBlock != nullptr && m_textBlockSizeChangedToken.Value != 0) + { + m_textBlock->SizeChanged -= m_textBlockSizeChangedToken; + m_textBlockSizeChangedToken.Value = 0; + } + if (m_scrollLeft != nullptr && m_scrollLeftClickToken.Value != 0) { m_scrollLeft->Click -= m_scrollLeftClickToken; @@ -128,6 +134,7 @@ void CalculationResult::OnApplyTemplate() if (m_textBlock) { m_textBlock->Visibility = ::Visibility::Visible; + m_textBlockSizeChangedToken = m_textBlock->SizeChanged += ref new SizeChangedEventHandler(this, &CalculationResult::OnTextBlockSizeChanged); } } UpdateVisualState(); @@ -417,3 +424,8 @@ void CalculationResult::OnTextContainerOnViewChanged(Object ^ /*sender*/, Scroll { UpdateScrollButtons(); } + +void CalculationResult::OnTextBlockSizeChanged(Object ^ /*sender*/, SizeChangedEventArgs ^ /*e*/) +{ + UpdateScrollButtons(); +} diff --git a/src/Calculator/Controls/CalculationResult.h b/src/Calculator/Controls/CalculationResult.h index 32910c2..8d2b6ca 100644 --- a/src/Calculator/Controls/CalculationResult.h +++ b/src/Calculator/Controls/CalculationResult.h @@ -56,6 +56,7 @@ namespace CalculatorApp void OnMinFontSizePropertyChanged(double oldValue, double newValue); void OnMaxFontSizePropertyChanged(double oldValue, double newValue); void OnTextContainerSizeChanged(Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e); + void OnTextBlockSizeChanged(Object ^ sender, Windows::UI::Xaml::SizeChangedEventArgs ^ e); void OnTextContainerLayoutUpdated(Object ^ sender, Object ^ e); void OnTextContainerOnViewChanged(Object ^ sender, Windows::UI::Xaml::Controls::ScrollViewerViewChangedEventArgs ^ e); void UpdateVisualState(); @@ -82,6 +83,7 @@ namespace CalculatorApp Windows::Foundation::EventRegistrationToken m_textContainerSizeChangedToken; Windows::Foundation::EventRegistrationToken m_scrollRightClickToken; Windows::Foundation::EventRegistrationToken m_scrollLeftClickToken; + Windows::Foundation::EventRegistrationToken m_textBlockSizeChangedToken; }; } }