check null before invoking event handlers (#12)

This commit is contained in:
Tian L 2021-04-13 18:41:53 +08:00 committed by GitHub
commit 813d76126b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 17 deletions

View file

@ -34,7 +34,7 @@ namespace CalculatorApp
if (newCurrentPosition != -1) if (newCurrentPosition != -1)
{ {
m_currentPosition = newCurrentPosition; m_currentPosition = newCurrentPosition;
CurrentChanged(this, null); CurrentChanged?.Invoke(this, null);
return true; return true;
} }
} }
@ -46,7 +46,7 @@ namespace CalculatorApp
{ {
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() => Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() =>
{ {
CurrentChanged(this, null); CurrentChanged?.Invoke(this, null);
})).AsTask().Wait(); })).AsTask().Wait();
} }
return false; return false;
@ -60,7 +60,7 @@ namespace CalculatorApp
} }
m_currentPosition = index; m_currentPosition = index;
CurrentChanged(this, null); CurrentChanged?.Invoke(this, null);
return true; return true;
} }
@ -219,7 +219,7 @@ namespace CalculatorApp
void OnSourceBindableVectorChanged(Windows.UI.Xaml.Interop.IBindableObservableVector source, object e) void OnSourceBindableVectorChanged(Windows.UI.Xaml.Interop.IBindableObservableVector source, object e)
{ {
Windows.Foundation.Collections.IVectorChangedEventArgs args = (Windows.Foundation.Collections.IVectorChangedEventArgs)e; Windows.Foundation.Collections.IVectorChangedEventArgs args = (Windows.Foundation.Collections.IVectorChangedEventArgs)e;
VectorChanged(this, args); VectorChanged?.Invoke(this, args);
} }
public event EventHandler<object> CurrentChanged; public event EventHandler<object> CurrentChanged;

View file

@ -406,7 +406,7 @@ namespace CalculatorApp
private void OnEquationButtonClicked(object sender, RoutedEventArgs e) private void OnEquationButtonClicked(object sender, RoutedEventArgs e)
{ {
EquationButtonClicked(this, new RoutedEventArgs()); EquationButtonClicked?.Invoke(this, new RoutedEventArgs());
SetEquationButtonTooltipAndAutomationName(); SetEquationButtonTooltipAndAutomationName();
} }
@ -424,7 +424,7 @@ namespace CalculatorApp
m_richEditBox.MathText = ""; m_richEditBox.MathText = "";
} }
RemoveButtonClicked(this, new RoutedEventArgs()); RemoveButtonClicked?.Invoke(this, new RoutedEventArgs());
if (m_functionButton != null) if (m_functionButton != null)
{ {
@ -452,7 +452,7 @@ namespace CalculatorApp
private void OnFunctionButtonClicked(object sender, RoutedEventArgs e) private void OnFunctionButtonClicked(object sender, RoutedEventArgs e)
{ {
KeyGraphFeaturesButtonClicked(this, new RoutedEventArgs()); KeyGraphFeaturesButtonClicked?.Invoke(this, new RoutedEventArgs());
} }
private void OnFunctionMenuButtonClicked(object sender, RoutedEventArgs e) private void OnFunctionMenuButtonClicked(object sender, RoutedEventArgs e)
@ -463,7 +463,7 @@ namespace CalculatorApp
m_richEditBox.SubmitEquation(EquationSubmissionSource.FOCUS_LOST); m_richEditBox.SubmitEquation(EquationSubmissionSource.FOCUS_LOST);
} }
KeyGraphFeaturesButtonClicked(this, new RoutedEventArgs()); KeyGraphFeaturesButtonClicked?.Invoke(this, new RoutedEventArgs());
} }
private void OnRichEditMenuOpened(object sender, object args) private void OnRichEditMenuOpened(object sender, object args)
@ -614,12 +614,12 @@ namespace CalculatorApp
} }
} }
EquationSubmitted(this, args); EquationSubmitted?.Invoke(this, args);
} }
private void OnEquationFormatRequested(object sender, MathRichEditBoxFormatRequest args) private void OnEquationFormatRequested(object sender, MathRichEditBoxFormatRequest args)
{ {
EquationFormatRequested(this, args); EquationFormatRequested?.Invoke(this, args);
} }
} }
} }

View file

@ -150,7 +150,7 @@ namespace CalculatorApp
{ {
// Request the final formatting of the text // Request the final formatting of the text
var formatRequest = new MathRichEditBoxFormatRequest(newVal); var formatRequest = new MathRichEditBoxFormatRequest(newVal);
FormatRequest(this, formatRequest); FormatRequest?.Invoke(this, formatRequest);
if (!string.IsNullOrEmpty(formatRequest.FormattedText)) if (!string.IsNullOrEmpty(formatRequest.FormattedText))
{ {
@ -158,11 +158,11 @@ namespace CalculatorApp
} }
SetValue(MathTextProperty, newVal); SetValue(MathTextProperty, newVal);
EquationSubmitted(this, new MathRichEditBoxSubmission(true, source)); EquationSubmitted?.Invoke(this, new MathRichEditBoxSubmission(true, source));
} }
else else
{ {
EquationSubmitted(this, new MathRichEditBoxSubmission(false, source)); EquationSubmitted?.Invoke(this, new MathRichEditBoxSubmission(false, source));
} }
} }

View file

@ -37,7 +37,7 @@ namespace CalculatorApp
private void Timer_Tick(object sender, object e) private void Timer_Tick(object sender, object e)
{ {
m_timer.Stop(); m_timer.Stop();
Action(this, null); Action?.Invoke(this, null);
} }
private DispatcherTimer m_timer; private DispatcherTimer m_timer;

View file

@ -407,7 +407,7 @@ namespace CalculatorApp
private void EquationTextBox_KeyGraphFeaturesButtonClicked(object sender, RoutedEventArgs e) private void EquationTextBox_KeyGraphFeaturesButtonClicked(object sender, RoutedEventArgs e)
{ {
KeyGraphFeaturesRequested(this, GetViewModelFromEquationTextBox(sender)); KeyGraphFeaturesRequested?.Invoke(this, GetViewModelFromEquationTextBox(sender));
} }
private void EquationTextBox_EquationButtonClicked(object sender, RoutedEventArgs e) private void EquationTextBox_EquationButtonClicked(object sender, RoutedEventArgs e)
@ -565,7 +565,7 @@ namespace CalculatorApp
private void EquationTextBox_EquationFormatRequested(object sender, MathRichEditBoxFormatRequest e) private void EquationTextBox_EquationFormatRequested(object sender, MathRichEditBoxFormatRequest e)
{ {
EquationFormatRequested(sender, e); EquationFormatRequested?.Invoke(sender, e);
} }
private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e) private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)

View file

@ -199,7 +199,7 @@ namespace CalculatorApp
private void AlwaysOnTopButton_Click(object sender, RoutedEventArgs e) private void AlwaysOnTopButton_Click(object sender, RoutedEventArgs e)
{ {
AlwaysOnTopClick(this, e); AlwaysOnTopClick?.Invoke(this, e);
} }
private Windows.ApplicationModel.Core.CoreApplicationViewTitleBar m_coreTitleBar; private Windows.ApplicationModel.Core.CoreApplicationViewTitleBar m_coreTitleBar;