diff --git a/src/Calculator/Common/KeyboardShortcutManager.cs b/src/Calculator/Common/KeyboardShortcutManager.cs index f9918b4b..141298bb 100644 --- a/src/Calculator/Common/KeyboardShortcutManager.cs +++ b/src/Calculator/Common/KeyboardShortcutManager.cs @@ -484,13 +484,8 @@ namespace CalculatorApp // Writer lock for the static maps lock (s_keyboardShortcutMapLockMutex) { - Control control = (target as ButtonBase); - - if (control == null) - { - // Handling Ctrl+E shortcut for Date Calc, target would be NavigationView^ in that case - control = (target as MUXC.NavigationView); - } + // Handling Ctrl+E shortcut for Date Calc, target would be NavigationView^ in that case + Control control = (target as ButtonBase) ?? (Control)(target as MUXC.NavigationView); int viewId = Utilities.GetWindowId(); @@ -580,7 +575,7 @@ namespace CalculatorApp private static bool CanNavigateModeByShortcut(MUXC.NavigationView navView, object nvi , ApplicationViewModel vm, ViewMode toMode) { - if (nvi != null && nvi is NavCategory navCategory) + if (nvi is NavCategory navCategory) { return navCategory.IsEnabled && navView.Visibility == Visibility.Visible @@ -601,21 +596,18 @@ namespace CalculatorApp { if (itemRef.Target is MUXC.NavigationView item) { - var navView = item; - - var menuItems = ((List)navView.MenuItemsSource); + var menuItems = ((List)item.MenuItemsSource); if (menuItems != null) { - var vm = (navView.DataContext as ApplicationViewModel); - if (null != vm) + if (item.DataContext is ApplicationViewModel vm) { - ViewMode realToMode = toMode.HasValue ? toMode.Value : NavCategoryStates.GetViewModeForVirtualKey(((MyVirtualKey)key)); + ViewMode realToMode = toMode ?? NavCategoryStates.GetViewModeForVirtualKey(((MyVirtualKey)key)); var nvi = menuItems[NavCategoryStates.GetFlatIndex(realToMode)]; - if (CanNavigateModeByShortcut(navView, nvi, vm, realToMode)) + if (CanNavigateModeByShortcut(item, nvi, vm, realToMode)) { vm.Mode = realToMode; - navView.SelectedItem = nvi; + item.SelectedItem = nvi; } } } @@ -685,14 +677,13 @@ namespace CalculatorApp { if (currentHonorShortcuts) { - var myVirtualKey = key; var lookupMap = GetCurrentKeyDictionary(isControlKeyPressed, isShiftKeyPressed, isAltKeyPressed); if (lookupMap == null) { return; } - var buttons = EqualRange(lookupMap, (MyVirtualKey)myVirtualKey); + var buttons = EqualRange(lookupMap, (MyVirtualKey)key); if (!buttons.Any()) { return; @@ -701,7 +692,7 @@ namespace CalculatorApp KeyboardShortcutManagerLocals.RunFirstEnabledButtonCommand(buttons); // Ctrl+C and Ctrl+V shifts focus to some button because of which enter doesn't work after copy/paste. So don't shift focus if Ctrl+C or Ctrl+V - // is pressed. When drop down is open, pressing escape shifts focus to clear button. So dont's shift focus if drop down is open. Ctrl+Insert is + // is pressed. When drop down is open, pressing escape shifts focus to clear button. So don't shift focus if drop down is open. Ctrl+Insert is // equivalent to Ctrl+C and Shift+Insert is equivalent to Ctrl+V //var currentIsDropDownOpen = s_IsDropDownOpen.find(viewId); if (!s_IsDropDownOpen.TryGetValue(viewId, out var currentIsDropDownOpen) || !currentIsDropDownOpen) @@ -778,13 +769,13 @@ namespace CalculatorApp { if (altPressed) { - if (!shiftKeyPressed) + if (shiftKeyPressed) { - return s_VirtualKeyAltChordsForButtons[viewId]; + return null; } else { - return null; + return s_VirtualKeyAltChordsForButtons[viewId]; } } else diff --git a/src/Calculator/Common/ValidatingConverters.cs b/src/Calculator/Common/ValidatingConverters.cs index b6e88bac..b7a49df6 100644 --- a/src/Calculator/Common/ValidatingConverters.cs +++ b/src/Calculator/Common/ValidatingConverters.cs @@ -44,15 +44,12 @@ namespace CalculatorApp { // The value to be valid has to be a boxed int32 value // extract that value and ensure it is valid, ie >= 0 - if (value != null) + if (value is Windows.Foundation.IPropertyValue box && box.Type == Windows.Foundation.PropertyType.Int32) { - if (value is Windows.Foundation.IPropertyValue box && box.Type == Windows.Foundation.PropertyType.Int32) + int index = box.GetInt32(); + if (index >= 0) { - int index = box.GetInt32(); - if (index >= 0) - { - return value; - } + return value; } } // The value is not valid therefore stop the binding right here diff --git a/src/Calculator/Converters/ExpressionItemTemplateSelector.cs b/src/Calculator/Converters/ExpressionItemTemplateSelector.cs index 086a9012..24ef1e74 100644 --- a/src/Calculator/Converters/ExpressionItemTemplateSelector.cs +++ b/src/Calculator/Converters/ExpressionItemTemplateSelector.cs @@ -16,8 +16,7 @@ namespace CalculatorApp { protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) { - DisplayExpressionToken token = (item as DisplayExpressionToken); - if (token != null) + if (item is DisplayExpressionToken token) { CalculatorApp.ViewModel.Common.TokenType type = token.Type; diff --git a/src/Calculator/Views/Calculator.xaml.cs b/src/Calculator/Views/Calculator.xaml.cs index a280b314..2ebb5137 100644 --- a/src/Calculator/Views/Calculator.xaml.cs +++ b/src/Calculator/Views/Calculator.xaml.cs @@ -814,8 +814,7 @@ namespace CalculatorApp private void DockPanelTapped(object sender, TappedRoutedEventArgs e) { - int index = DockPivot.SelectedIndex; - if (index == 1 && !IsProgrammer) + if (DockPivot.SelectedIndex == 1 && !IsProgrammer) { SetChildAsMemory(); } diff --git a/src/Calculator/Views/CalculatorProgrammerDisplayPanel.xaml.cs b/src/Calculator/Views/CalculatorProgrammerDisplayPanel.xaml.cs index 3d87273f..8803dc4b 100644 --- a/src/Calculator/Views/CalculatorProgrammerDisplayPanel.xaml.cs +++ b/src/Calculator/Views/CalculatorProgrammerDisplayPanel.xaml.cs @@ -36,7 +36,7 @@ namespace CalculatorApp { get { - Debug.Assert(DataContext as ViewModel.StandardCalculatorViewModel != null, "static_cast result must NOT be null"); + Debug.Assert(DataContext is ViewModel.StandardCalculatorViewModel, "static_cast result must NOT be null"); return DataContext as ViewModel.StandardCalculatorViewModel; } } diff --git a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs index 80f206b4..8bb2ee79 100644 --- a/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs +++ b/src/Calculator/Views/GraphingCalculator/GraphingCalculator.xaml.cs @@ -518,7 +518,7 @@ namespace CalculatorApp private void GraphingControl_LosingFocus(UIElement sender, LosingFocusEventArgs args) { - if (!(args.NewFocusedElement is FrameworkElement newFocusElement) || newFocusElement.Name == null) + if (!(args.NewFocusedElement is FrameworkElement)) { // Because clicking on the swap chain panel will try to move focus to a control that can't actually take focus // we will get a null destination. So we are going to try and cancel that request. @@ -534,15 +534,7 @@ namespace CalculatorApp private void GraphingControl_GraphViewChangedEvent(object sender, GraphViewChangedReason reason) { - if (reason == GraphViewChangedReason.Manipulation) - { - IsManualAdjustment = true; - } - else - { - IsManualAdjustment = false; - } - + IsManualAdjustment = (reason == GraphViewChangedReason.Manipulation); UpdateGraphAutomationName(); var announcement = CalculatorAnnouncement.GetGraphViewChangedAnnouncement(GraphControlAutomationName); diff --git a/src/Calculator/Views/HistoryList.xaml.cs b/src/Calculator/Views/HistoryList.xaml.cs index 13f67e91..639c6dee 100644 --- a/src/Calculator/Views/HistoryList.xaml.cs +++ b/src/Calculator/Views/HistoryList.xaml.cs @@ -48,11 +48,8 @@ namespace CalculatorApp private void ListView_ItemClick(object sender, ItemClickEventArgs e) { - HistoryViewModel historyVM = (DataContext as HistoryViewModel); - HistoryItemViewModel clickedItem = (e.ClickedItem as HistoryItemViewModel); - // When the user clears the history list in the overlay view and presses enter, the clickedItem is nullptr - if (clickedItem != null && historyVM != null) + if (e.ClickedItem is HistoryItemViewModel clickedItem && DataContext is HistoryViewModel historyVM) { historyVM.ShowItem(clickedItem); } @@ -60,8 +57,7 @@ namespace CalculatorApp private void OnCopyMenuItemClicked(object sender, RoutedEventArgs e) { var listViewItem = HistoryContextMenu.Target; - var itemViewModel = (HistoryListView.ItemFromContainer(listViewItem) as HistoryItemViewModel); - if (itemViewModel != null) + if (HistoryListView.ItemFromContainer(listViewItem) is HistoryItemViewModel itemViewModel) { CopyPasteManager.CopyToClipboard(itemViewModel.Result); } @@ -69,16 +65,14 @@ namespace CalculatorApp private void OnDeleteMenuItemClicked(object sender, RoutedEventArgs e) { var listViewItem = HistoryContextMenu.Target; - var itemViewModel = (HistoryListView.ItemFromContainer(listViewItem) as HistoryItemViewModel); - if (itemViewModel != null) + if (HistoryListView.ItemFromContainer(listViewItem) is HistoryItemViewModel itemViewModel) { Model.DeleteItem(itemViewModel); } } private void OnDeleteSwipeInvoked(MUXC.SwipeItem sender, MUXC.SwipeItemInvokedEventArgs e) { - var swipedItem = (e.SwipeControl.DataContext as HistoryItemViewModel); - if (swipedItem != null) + if (e.SwipeControl.DataContext is HistoryItemViewModel swipedItem) { Model.DeleteItem(swipedItem); } diff --git a/src/Calculator/Views/MainPage.xaml.cs b/src/Calculator/Views/MainPage.xaml.cs index b2dbab7c..bd4a56c4 100644 --- a/src/Calculator/Views/MainPage.xaml.cs +++ b/src/Calculator/Views/MainPage.xaml.cs @@ -368,8 +368,7 @@ namespace CalculatorApp return; } - var item = (e.SelectedItemContainer as MUXC.NavigationViewItem); - if (item != null) + if (e.SelectedItemContainer is MUXC.NavigationViewItem item) { Model.Mode = (ViewMode)item.Tag; }