mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-21 22:03:11 -07:00
Fix C# warnings
A continuation of my last PR. A continuation of my last PR. No behavioral changes, just C# modernizations as well as marking some properties to be readonly since they aren't modified.
This commit is contained in:
parent
f27bdba85a
commit
d2017fbf3b
42 changed files with 283 additions and 505 deletions
|
@ -30,7 +30,7 @@ namespace CalculatorApp
|
|||
{
|
||||
namespace ApplicationResourceKeys
|
||||
{
|
||||
public static partial class Globals
|
||||
public static class Globals
|
||||
{
|
||||
public static readonly string AppMinWindowHeight = "AppMinWindowHeight";
|
||||
public static readonly string AppMinWindowWidth = "AppMinWindowWidth";
|
||||
|
@ -224,78 +224,74 @@ namespace CalculatorApp
|
|||
if (!m_preLaunched)
|
||||
{
|
||||
var newCoreAppView = CoreApplication.CreateNewView();
|
||||
_ = newCoreAppView.Dispatcher.RunAsync(
|
||||
CoreDispatcherPriority.Normal, async () =>
|
||||
|
||||
async void AgileCallback()
|
||||
{
|
||||
if (weak.Target is App that)
|
||||
{
|
||||
if (weak.Target is App that)
|
||||
var newRootFrame = App.CreateFrame();
|
||||
|
||||
SetMinWindowSizeAndThemeAndActivate(newRootFrame, minWindowSize);
|
||||
|
||||
if (!newRootFrame.Navigate(typeof(MainPage), argument))
|
||||
{
|
||||
var newRootFrame = App.CreateFrame();
|
||||
// We couldn't navigate to the main page, kill the app so we have a good
|
||||
// stack to debug
|
||||
throw new SystemException();
|
||||
}
|
||||
|
||||
SetMinWindowSizeAndThemeAndActivate(newRootFrame, minWindowSize);
|
||||
var frameService = WindowFrameService.CreateNewWindowFrameService(newRootFrame, true, weak);
|
||||
that.AddWindowToMap(frameService);
|
||||
|
||||
if (!newRootFrame.Navigate(typeof(MainPage), argument))
|
||||
var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
|
||||
|
||||
// CSHARP_MIGRATION_ANNOTATION:
|
||||
// class SafeFrameWindowCreation is being interpreted into a IDisposable class
|
||||
// in order to enhance its RAII capability that was written in C++/CX
|
||||
using (var safeFrameServiceCreation = new SafeFrameWindowCreation(frameService, that))
|
||||
{
|
||||
int newWindowId = ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread());
|
||||
|
||||
ActivationViewSwitcher activationViewSwitcher = null;
|
||||
if (args is IViewSwitcherProvider activateEventArgs)
|
||||
{
|
||||
// We couldn't navigate to the main page, kill the app so we have a good
|
||||
// stack to debug
|
||||
throw new SystemException();
|
||||
activationViewSwitcher = activateEventArgs.ViewSwitcher;
|
||||
}
|
||||
|
||||
var frameService = WindowFrameService.CreateNewWindowFrameService(newRootFrame, true, weak);
|
||||
that.AddWindowToMap(frameService);
|
||||
|
||||
var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
|
||||
|
||||
// CSHARP_MIGRATION_ANNOTATION:
|
||||
// class SafeFrameWindowCreation is being interpreted into a IDisposable class
|
||||
// in order to enhance its RAII capability that was written in C++/CX
|
||||
using (var safeFrameServiceCreation = new SafeFrameWindowCreation(frameService, that))
|
||||
if (activationViewSwitcher != null)
|
||||
{
|
||||
int newWindowId = ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread());
|
||||
|
||||
ActivationViewSwitcher activationViewSwitcher = null;
|
||||
var activateEventArgs = (args as IViewSwitcherProvider);
|
||||
if (activateEventArgs != null)
|
||||
_ = activationViewSwitcher.ShowAsStandaloneAsync(newWindowId, ViewSizePreference.Default);
|
||||
safeFrameServiceCreation.SetOperationSuccess(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((args is IApplicationViewActivatedEventArgs activatedEventArgs) && (activatedEventArgs.CurrentlyShownApplicationViewId != 0))
|
||||
{
|
||||
activationViewSwitcher = activateEventArgs.ViewSwitcher;
|
||||
}
|
||||
|
||||
if (activationViewSwitcher != null)
|
||||
{
|
||||
_ = activationViewSwitcher.ShowAsStandaloneAsync(newWindowId, ViewSizePreference.Default);
|
||||
safeFrameServiceCreation.SetOperationSuccess(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
var activatedEventArgs = (args as IApplicationViewActivatedEventArgs);
|
||||
if ((activatedEventArgs != null) && (activatedEventArgs.CurrentlyShownApplicationViewId != 0))
|
||||
{
|
||||
// CSHARP_MIGRATION_ANNOTATION:
|
||||
// here we don't use ContinueWith() to interpret origin code because we would like to
|
||||
// pursue the design of class SafeFrameWindowCreate whichi was using RAII to ensure
|
||||
// some states get handled properly when its instance is being destructed.
|
||||
//
|
||||
// To achieve that, SafeFrameWindowCreate has been reinterpreted using IDisposable
|
||||
// pattern, which forces we use below way to keep async works being controlled within
|
||||
// a same code block.
|
||||
var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
|
||||
frameService.GetViewId(),
|
||||
ViewSizePreference.Default,
|
||||
activatedEventArgs.CurrentlyShownApplicationViewId,
|
||||
ViewSizePreference.Default);
|
||||
// SafeFrameServiceCreation is used to automatically remove the frame
|
||||
// from the list of frames if something goes bad.
|
||||
safeFrameServiceCreation.SetOperationSuccess(viewShown);
|
||||
}
|
||||
// CSHARP_MIGRATION_ANNOTATION:
|
||||
// here we don't use ContinueWith() to interpret origin code because we would like to
|
||||
// pursue the design of class SafeFrameWindowCreate whichi was using RAII to ensure
|
||||
// some states get handled properly when its instance is being destructed.
|
||||
//
|
||||
// To achieve that, SafeFrameWindowCreate has been reinterpreted using IDisposable
|
||||
// pattern, which forces we use below way to keep async works being controlled within
|
||||
// a same code block.
|
||||
var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(frameService.GetViewId(), ViewSizePreference.Default, activatedEventArgs.CurrentlyShownApplicationViewId, ViewSizePreference.Default);
|
||||
// SafeFrameServiceCreation is used to automatically remove the frame
|
||||
// from the list of frames if something goes bad.
|
||||
safeFrameServiceCreation.SetOperationSuccess(viewShown);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_ = newCoreAppView.Dispatcher.RunAsync(
|
||||
CoreDispatcherPriority.Normal, AgileCallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
ActivationViewSwitcher activationViewSwitcher = null;
|
||||
var activateEventArgs = (args as IViewSwitcherProvider);
|
||||
if (activateEventArgs != null)
|
||||
if (args is IViewSwitcherProvider activateEventArgs)
|
||||
{
|
||||
activationViewSwitcher = activateEventArgs.ViewSwitcher;
|
||||
}
|
||||
|
@ -334,14 +330,13 @@ namespace CalculatorApp
|
|||
// for tablet mode: since system view activation policy is disabled so do ShowAsStandaloneAsync if activationViewSwitcher exists in
|
||||
// activationArgs
|
||||
ActivationViewSwitcher activationViewSwitcher = null;
|
||||
var activateEventArgs = (args as IViewSwitcherProvider);
|
||||
if (activateEventArgs != null)
|
||||
if (args is IViewSwitcherProvider activateEventArgs)
|
||||
{
|
||||
activationViewSwitcher = activateEventArgs.ViewSwitcher;
|
||||
}
|
||||
if (activationViewSwitcher != null)
|
||||
{
|
||||
var viewId = (args as IApplicationViewActivatedEventArgs).CurrentlyShownApplicationViewId;
|
||||
var viewId = ((IApplicationViewActivatedEventArgs)args).CurrentlyShownApplicationViewId;
|
||||
if (viewId != 0)
|
||||
{
|
||||
_ = activationViewSwitcher.ShowAsStandaloneAsync(viewId);
|
||||
|
@ -404,7 +399,7 @@ namespace CalculatorApp
|
|||
private readonly WindowFrameService m_frameService;
|
||||
private bool m_frameOpenedInWindow;
|
||||
private readonly App m_parent;
|
||||
};
|
||||
}
|
||||
|
||||
private async Task SetupJumpList()
|
||||
{
|
||||
|
@ -425,7 +420,7 @@ namespace CalculatorApp
|
|||
ViewMode mode = option.ViewMode;
|
||||
var item = JumpListItem.CreateWithArguments(((int)mode).ToString(), "ms-resource:///Resources/" + NavCategoryStates.GetNameResourceKey(mode));
|
||||
item.Description = "ms-resource:///Resources/" + NavCategoryStates.GetNameResourceKey(mode);
|
||||
item.Logo = new Uri("ms-appx:///Assets/" + mode.ToString() + ".png");
|
||||
item.Logo = new Uri("ms-appx:///Assets/" + mode + ".png");
|
||||
|
||||
jumpList.Items.Add(item);
|
||||
}
|
||||
|
@ -469,33 +464,13 @@ namespace CalculatorApp
|
|||
}
|
||||
}
|
||||
|
||||
private WindowFrameService GetWindowFromMap(int viewId)
|
||||
{
|
||||
m_windowsMapLock.EnterReadLock();
|
||||
try
|
||||
{
|
||||
if (m_secondaryWindows.TryGetValue(viewId, out var windowMapEntry))
|
||||
{
|
||||
return windowMapEntry;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
m_windowsMapLock.ExitReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveWindowFromMap(int viewId)
|
||||
{
|
||||
m_windowsMapLock.EnterWriteLock();
|
||||
try
|
||||
{
|
||||
bool removed = m_secondaryWindows.Remove(viewId);
|
||||
Debug.Assert(removed != false, "Window does not exist in the list");
|
||||
Debug.Assert(removed, "Window does not exist in the list");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
|
@ -44,10 +44,10 @@ namespace CalculatorApp
|
|||
// restore the selection to the way we wanted it to begin with
|
||||
if (CurrentPosition >= 0 && CurrentPosition < m_source.Count)
|
||||
{
|
||||
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() =>
|
||||
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
CurrentChanged?.Invoke(this, null);
|
||||
})).AsTask().Wait();
|
||||
}).AsTask().Wait();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -196,10 +196,6 @@ namespace CalculatorApp
|
|||
|
||||
public sealed class AlwaysSelectedCollectionViewConverter : Windows.UI.Xaml.Data.IValueConverter
|
||||
{
|
||||
public AlwaysSelectedCollectionViewConverter()
|
||||
{
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is IList result)
|
||||
|
|
|
@ -115,10 +115,6 @@ namespace CalculatorApp
|
|||
|
||||
public sealed class KeyboardShortcutManager : DependencyObject
|
||||
{
|
||||
public KeyboardShortcutManager()
|
||||
{
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CharacterProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"Character",
|
||||
|
@ -484,13 +480,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 +571,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 +592,18 @@ namespace CalculatorApp
|
|||
{
|
||||
if (itemRef.Target is MUXC.NavigationView item)
|
||||
{
|
||||
var navView = item;
|
||||
|
||||
var menuItems = ((List<object>)navView.MenuItemsSource);
|
||||
var menuItems = ((List<object>)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 +673,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 +688,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 +765,13 @@ namespace CalculatorApp
|
|||
{
|
||||
if (altPressed)
|
||||
{
|
||||
if (!shiftKeyPressed)
|
||||
if (shiftKeyPressed)
|
||||
{
|
||||
return s_VirtualKeyAltChordsForButtons[viewId];
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
return s_VirtualKeyAltChordsForButtons[viewId];
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
using System;
|
||||
|
||||
|
@ -8,9 +8,6 @@ namespace CalculatorApp
|
|||
{
|
||||
public sealed class ValidSelectedItemConverter : Windows.UI.Xaml.Data.IValueConverter
|
||||
{
|
||||
public ValidSelectedItemConverter()
|
||||
{ }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
// Pass through as we don't want to change the value from the source
|
||||
|
@ -31,9 +28,6 @@ namespace CalculatorApp
|
|||
|
||||
public sealed class ValidSelectedIndexConverter : Windows.UI.Xaml.Data.IValueConverter
|
||||
{
|
||||
public ValidSelectedIndexConverter()
|
||||
{ }
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
// Pass through as we don't want to change the value from the source
|
||||
|
@ -44,15 +38,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
|
||||
|
|
|
@ -33,11 +33,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for MinFontSize. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty MinFontSizeProperty =
|
||||
DependencyProperty.Register(nameof(MinFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(0.0, new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(MinFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(0.0, (sender, args) =>
|
||||
{
|
||||
var self = (CalculationResult)sender;
|
||||
self.OnMinFontSizePropertyChanged((double)args.OldValue, (double)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public double MaxFontSize
|
||||
{
|
||||
|
@ -47,11 +47,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for MaxFontSize. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty MaxFontSizeProperty =
|
||||
DependencyProperty.Register(nameof(MaxFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(30.0, new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(MaxFontSize), typeof(double), typeof(CalculationResult), new PropertyMetadata(30.0, (sender, args) =>
|
||||
{
|
||||
var self = (CalculationResult)sender;
|
||||
self.OnMaxFontSizePropertyChanged((double)args.OldValue, (double)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public Thickness DisplayMargin
|
||||
{
|
||||
|
@ -71,11 +71,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for IsActive. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty IsActiveProperty =
|
||||
DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), (sender, args) =>
|
||||
{
|
||||
var self = (CalculationResult)sender;
|
||||
self.OnIsActivePropertyChanged((bool)args.OldValue, (bool)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public string DisplayValue
|
||||
{
|
||||
|
@ -85,11 +85,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for DisplayValue. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty DisplayValueProperty =
|
||||
DependencyProperty.Register(nameof(DisplayValue), typeof(string), typeof(CalculationResult), new PropertyMetadata(string.Empty, new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(DisplayValue), typeof(string), typeof(CalculationResult), new PropertyMetadata(string.Empty, (sender, args) =>
|
||||
{
|
||||
var self = (CalculationResult)sender;
|
||||
self.OnDisplayValuePropertyChanged((string)args.OldValue, (string)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public bool IsInError
|
||||
{
|
||||
|
@ -99,11 +99,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for IsInError. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty IsInErrorProperty =
|
||||
DependencyProperty.Register(nameof(IsInError), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(IsInError), typeof(bool), typeof(CalculationResult), new PropertyMetadata(default(bool), (sender, args) =>
|
||||
{
|
||||
var self = (CalculationResult)sender;
|
||||
self.OnIsInErrorPropertyChanged((bool)args.OldValue, (bool)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public bool IsOperatorCommand
|
||||
{
|
||||
|
@ -151,7 +151,7 @@ namespace CalculatorApp
|
|||
|
||||
if (widthDiff > WIDTHCUTOFF)
|
||||
{
|
||||
fontSizeChange = Math.Min((double)Math.Max((double)Math.Floor(WIDTHTOFONTSCALAR * widthDiff) - WIDTHTOFONTOFFSET, INCREMENTOFFSET), MAXFONTINCREMENT);
|
||||
fontSizeChange = Math.Min(Math.Max(Math.Floor(WIDTHTOFONTSCALAR * widthDiff) - WIDTHTOFONTOFFSET, INCREMENTOFFSET), MAXFONTINCREMENT);
|
||||
}
|
||||
if (m_textBlock.ActualWidth < containerSize && Math.Abs(m_textBlock.FontSize - MaxFontSize) > FONTTOLERANCE && !m_haveCalculatedMax)
|
||||
{
|
||||
|
|
|
@ -33,11 +33,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for ButtonId. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty ButtonIdProperty =
|
||||
DependencyProperty.Register(nameof(ButtonId), typeof(NumbersAndOperatorsEnum), typeof(CalculatorButton), new PropertyMetadata(default(NumbersAndOperatorsEnum), new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(ButtonId), typeof(NumbersAndOperatorsEnum), typeof(CalculatorButton), new PropertyMetadata(default(NumbersAndOperatorsEnum), (sender, args) =>
|
||||
{
|
||||
var self = (CalculatorButton)sender;
|
||||
self.OnButtonIdPropertyChanged((NumbersAndOperatorsEnum)args.OldValue, (NumbersAndOperatorsEnum)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public string AuditoryFeedback
|
||||
{
|
||||
|
@ -47,11 +47,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for AuditoryFeedback. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty AuditoryFeedbackProperty =
|
||||
DependencyProperty.Register(nameof(AuditoryFeedback), typeof(string), typeof(CalculatorButton), new PropertyMetadata(string.Empty, new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(AuditoryFeedback), typeof(string), typeof(CalculatorButton), new PropertyMetadata(string.Empty, (sender, args) =>
|
||||
{
|
||||
var self = (CalculatorButton)sender;
|
||||
self.OnAuditoryFeedbackPropertyChanged((string)args.OldValue, (string)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public Windows.UI.Xaml.Media.Brush HoverBackground
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using CalculatorApp.ViewModel.Common;
|
||||
|
@ -16,10 +16,6 @@ namespace CalculatorApp
|
|||
{
|
||||
public sealed class EquationTextBox : Windows.UI.Xaml.Controls.Control
|
||||
{
|
||||
public EquationTextBox()
|
||||
{
|
||||
}
|
||||
|
||||
public Windows.UI.Xaml.Media.SolidColorBrush EquationColor
|
||||
{
|
||||
get => (Windows.UI.Xaml.Media.SolidColorBrush)GetValue(EquationColorProperty);
|
||||
|
|
|
@ -10,10 +10,6 @@ namespace CalculatorApp
|
|||
{
|
||||
public sealed class OperatorPanelButton : Windows.UI.Xaml.Controls.Primitives.ToggleButton
|
||||
{
|
||||
public OperatorPanelButton()
|
||||
{
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get => (string)GetValue(TextProperty);
|
||||
|
|
|
@ -12,10 +12,6 @@ namespace CalculatorApp
|
|||
{
|
||||
public sealed class OperatorPanelListView : Windows.UI.Xaml.Controls.ListView
|
||||
{
|
||||
public OperatorPanelListView()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate()
|
||||
{
|
||||
m_scrollViewer = GetTemplateChild("ScrollViewer") as ScrollViewer;
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace CalculatorApp
|
|||
{
|
||||
InLine,
|
||||
Above
|
||||
};
|
||||
}
|
||||
|
||||
public sealed class OverflowTextBlock : Windows.UI.Xaml.Controls.Control
|
||||
{
|
||||
|
@ -37,11 +37,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for TokensUpdated. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty TokensUpdatedProperty =
|
||||
DependencyProperty.Register(nameof(TokensUpdated), typeof(bool), typeof(OverflowTextBlock), new PropertyMetadata(default(bool), new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(TokensUpdated), typeof(bool), typeof(OverflowTextBlock), new PropertyMetadata(default(bool), (sender, args) =>
|
||||
{
|
||||
var self = (OverflowTextBlock)sender;
|
||||
self.OnTokensUpdatedPropertyChanged((bool)args.OldValue, (bool)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public OverflowButtonPlacement ScrollButtonsPlacement
|
||||
{
|
||||
|
@ -51,11 +51,11 @@ namespace CalculatorApp
|
|||
|
||||
// Using a DependencyProperty as the backing store for ScrollButtonsPlacement. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty ScrollButtonsPlacementProperty =
|
||||
DependencyProperty.Register(nameof(ScrollButtonsPlacement), typeof(OverflowButtonPlacement), typeof(OverflowTextBlock), new PropertyMetadata(default(OverflowButtonPlacement), new PropertyChangedCallback((sender, args) =>
|
||||
DependencyProperty.Register(nameof(ScrollButtonsPlacement), typeof(OverflowButtonPlacement), typeof(OverflowTextBlock), new PropertyMetadata(default(OverflowButtonPlacement), (sender, args) =>
|
||||
{
|
||||
var self = (OverflowTextBlock)sender;
|
||||
self.OnScrollButtonsPlacementPropertyChanged((OverflowButtonPlacement)args.OldValue, (OverflowButtonPlacement)args.NewValue);
|
||||
})));
|
||||
}));
|
||||
|
||||
public bool IsActive
|
||||
{
|
||||
|
|
|
@ -9,9 +9,6 @@ namespace CalculatorApp
|
|||
{
|
||||
public sealed class RadixButton : Windows.UI.Xaml.Controls.RadioButton
|
||||
{
|
||||
public RadixButton()
|
||||
{ }
|
||||
|
||||
internal string GetRawDisplayValue()
|
||||
{
|
||||
string radixContent = Content?.ToString();
|
||||
|
|
|
@ -16,10 +16,6 @@ namespace CalculatorApp
|
|||
{
|
||||
public sealed class SupplementaryItemsControl : ItemsControl
|
||||
{
|
||||
public SupplementaryItemsControl()
|
||||
{
|
||||
}
|
||||
|
||||
protected override DependencyObject GetContainerForItemOverride()
|
||||
{
|
||||
return new SupplementaryContentPresenter();
|
||||
|
@ -38,10 +34,6 @@ namespace CalculatorApp
|
|||
|
||||
public sealed class SupplementaryContentPresenter : ContentPresenter
|
||||
{
|
||||
public SupplementaryContentPresenter()
|
||||
{
|
||||
}
|
||||
|
||||
protected override AutomationPeer OnCreateAutomationPeer()
|
||||
{
|
||||
return new SupplementaryContentPresenterAP(this);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using CalculatorApp.ViewModel.Common;
|
||||
|
@ -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;
|
||||
|
||||
|
|
|
@ -42,8 +42,6 @@ namespace CalculatorApp
|
|||
convertedValue = resourceLoader.GetResourceString("Hex");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return convertedValue;
|
||||
|
|
|
@ -11,10 +11,6 @@ namespace CalculatorApp
|
|||
{
|
||||
public sealed class KeyGraphFeaturesTemplateSelector : Windows.UI.Xaml.Controls.DataTemplateSelector
|
||||
{
|
||||
public KeyGraphFeaturesTemplateSelector()
|
||||
{
|
||||
}
|
||||
|
||||
public Windows.UI.Xaml.DataTemplate RichEditTemplate { get; set; }
|
||||
public Windows.UI.Xaml.DataTemplate GridTemplate { get; set; }
|
||||
public Windows.UI.Xaml.DataTemplate TextBlockTemplate { get; set; }
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace CalculatorApp.Utils
|
|||
if (callbackToken.RootFrame.IsAlive)
|
||||
{
|
||||
Frame rootFrame = callbackToken.RootFrame.Target as Frame;
|
||||
rootFrame.UnregisterPropertyChangedCallback(Frame.RequestedThemeProperty, callbackToken.Token);
|
||||
rootFrame.UnregisterPropertyChangedCallback(FrameworkElement.RequestedThemeProperty, callbackToken.Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
using System;
|
||||
|
@ -54,7 +54,7 @@ namespace Calculator.Utils
|
|||
/// <param name="element">Parent element.</param>
|
||||
/// <param name="typeName">Type of descendant.</param>
|
||||
/// <returns>Descendant control or null if not found.</returns>
|
||||
private static DependencyObject FindDescendant(DependencyObject element, Type typeName)
|
||||
internal static DependencyObject FindDescendant(DependencyObject element, Type typeName)
|
||||
{
|
||||
DependencyObject retValue = null;
|
||||
var childrenCount = VisualTreeHelper.GetChildrenCount(element);
|
||||
|
@ -85,7 +85,7 @@ namespace Calculator.Utils
|
|||
/// <param name="element">Parent element.</param>
|
||||
/// <param name="name">Name of the control to find</param>
|
||||
/// <returns>Descendant control or null if not found.</returns>
|
||||
private static FrameworkElement FindAscendantByName(DependencyObject element, string name)
|
||||
internal static FrameworkElement FindAscendantByName(DependencyObject element, string name)
|
||||
{
|
||||
if (element == null || name == null || name.Length == 0)
|
||||
{
|
||||
|
@ -113,7 +113,7 @@ namespace Calculator.Utils
|
|||
/// <param name="element">Child element.</param>
|
||||
/// <param name="type">Type of ascendant to look for.</param>
|
||||
/// <returns>Ascendant control or null if not found.</returns>
|
||||
private static object FindAscendant(DependencyObject element, Type typeName)
|
||||
internal static object FindAscendant(DependencyObject element, Type typeName)
|
||||
{
|
||||
var parent = VisualTreeHelper.GetParent(element);
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ namespace CalculatorApp
|
|||
string memoryPaneName = AppResourceProvider.GetInstance().GetResourceString("MemoryPane");
|
||||
MemoryFlyout.FlyoutPresenterStyle.Setters.Add(new Setter(AutomationProperties.NameProperty, memoryPaneName));
|
||||
|
||||
if (Windows.Foundation.Metadata.ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.Primitives.FlyoutBase", "Closing"))
|
||||
if (Windows.Foundation.Metadata.ApiInformation.IsEventPresent("Windows.UI.Xaml.Controls.Primitives.FlyoutBase", nameof(FlyoutBase.Closing)))
|
||||
{
|
||||
HistoryFlyout.Closing += HistoryFlyout_Closing;
|
||||
MemoryFlyout.Closing += OnMemoryFlyoutClosing;
|
||||
|
@ -234,7 +234,7 @@ namespace CalculatorApp
|
|||
// Delay load things later when we get a chance.
|
||||
WeakReference weakThis = new WeakReference(this);
|
||||
_ = this.Dispatcher.RunAsync(
|
||||
CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
if (TraceLogger.GetInstance().IsWindowIdInLog(ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread())))
|
||||
{
|
||||
|
@ -243,7 +243,7 @@ namespace CalculatorApp
|
|||
refThis.GetMemory();
|
||||
}
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void LoadResourceStrings()
|
||||
|
@ -533,7 +533,7 @@ namespace CalculatorApp
|
|||
|
||||
// Since we need different font sizes for different numeric system,
|
||||
// we use a table of optimal font sizes for each numeric system.
|
||||
private static readonly FontTable[] fontTables = new FontTable[] {
|
||||
private static readonly FontTable[] fontTables = {
|
||||
new FontTable { numericSystem = "Arab", fullFont = 104, fullFontMin = 29.333, portraitMin = 23, snapFont = 40,
|
||||
fullNumPadFont = 56, snapScientificNumPadFont = 40, portraitScientificNumPadFont = 56 },
|
||||
new FontTable { numericSystem = "ArabExt", fullFont = 104, fullFontMin = 29.333, portraitMin = 23, snapFont = 40,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,37 +58,25 @@ namespace CalculatorApp
|
|||
private void DecButtonChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TraceLogger.GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum.DecButton, ViewMode.Programmer);
|
||||
if (Model != null)
|
||||
{
|
||||
Model.SwitchProgrammerModeBase(NumberBase.DecBase);
|
||||
}
|
||||
Model?.SwitchProgrammerModeBase(NumberBase.DecBase);
|
||||
}
|
||||
|
||||
private void HexButtonChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TraceLogger.GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum.HexButton, ViewMode.Programmer);
|
||||
if (Model != null)
|
||||
{
|
||||
Model.SwitchProgrammerModeBase(NumberBase.HexBase);
|
||||
}
|
||||
Model?.SwitchProgrammerModeBase(NumberBase.HexBase);
|
||||
}
|
||||
|
||||
private void BinButtonChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TraceLogger.GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum.BinButton, ViewMode.Programmer);
|
||||
if (Model != null)
|
||||
{
|
||||
Model.SwitchProgrammerModeBase(NumberBase.BinBase);
|
||||
}
|
||||
Model?.SwitchProgrammerModeBase(NumberBase.BinBase);
|
||||
}
|
||||
|
||||
private void OctButtonChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
TraceLogger.GetInstance().UpdateButtonUsage(NumbersAndOperatorsEnum.OctButton, ViewMode.Programmer);
|
||||
if (Model != null)
|
||||
{
|
||||
Model.SwitchProgrammerModeBase(NumberBase.OctBase);
|
||||
}
|
||||
Model?.SwitchProgrammerModeBase(NumberBase.OctBase);
|
||||
}
|
||||
|
||||
private void OnCopyMenuItemClicked(object sender, RoutedEventArgs e)
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace CalculatorApp
|
|||
LogicalShift,
|
||||
RotateCircular,
|
||||
RotateCarry
|
||||
};
|
||||
}
|
||||
|
||||
private void BitshiftFlyout_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
|
|
@ -124,11 +124,11 @@ namespace CalculatorApp
|
|||
{
|
||||
InverseHyperbolicTrigFunctions.Visibility = Visibility.Visible;
|
||||
}
|
||||
else if (isShiftChecked && !isHypeChecked)
|
||||
else if (isShiftChecked)
|
||||
{
|
||||
InverseTrigFunctions.Visibility = Visibility.Visible;
|
||||
}
|
||||
else if (!isShiftChecked && isHypeChecked)
|
||||
else if (isHypeChecked)
|
||||
{
|
||||
HyperbolicTrigFunctions.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
|
|
@ -258,8 +258,7 @@ namespace CalculatorApp
|
|||
}
|
||||
|
||||
if (submission.Source == EquationSubmissionSource.ENTER_KEY
|
||||
|| (submission.Source == EquationSubmissionSource.FOCUS_LOST && submission.HasTextChanged && eq.Expression != null
|
||||
&& eq.Expression.Length > 0))
|
||||
|| (submission.Source == EquationSubmissionSource.FOCUS_LOST && submission.HasTextChanged && !string.IsNullOrEmpty(eq.Expression)))
|
||||
{
|
||||
if (submission.Source == EquationSubmissionSource.ENTER_KEY)
|
||||
{
|
||||
|
@ -355,13 +354,13 @@ namespace CalculatorApp
|
|||
{
|
||||
|
||||
WeakReference weakThis = new WeakReference(this);
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
if (weakThis.Target is EquationInputArea refThis && refThis.m_isHighContrast == refThis.m_accessibilitySettings.HighContrast)
|
||||
{
|
||||
refThis.ReloadAvailableColors(false, false);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void EquationTextBox_RemoveButtonClicked(object sender, RoutedEventArgs e)
|
||||
|
@ -436,10 +435,7 @@ namespace CalculatorApp
|
|||
if (index >= 0)
|
||||
{
|
||||
var container = (UIElement)EquationInputList.ContainerFromIndex(index);
|
||||
if (container != null)
|
||||
{
|
||||
container.StartBringIntoView();
|
||||
}
|
||||
container?.StartBringIntoView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -466,10 +462,7 @@ namespace CalculatorApp
|
|||
if (index >= 0)
|
||||
{
|
||||
var container = (UIElement)EquationInputList.ContainerFromIndex(index);
|
||||
if (container != null)
|
||||
{
|
||||
container.StartBringIntoView();
|
||||
}
|
||||
container?.StartBringIntoView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -594,11 +587,11 @@ namespace CalculatorApp
|
|||
{
|
||||
TimeSpan timeSpan = new TimeSpan(10000000); // 1 tick = 100 nanoseconds, and 10000000 ticks = 1 second.
|
||||
DispatcherTimerDelayer delayer = new DispatcherTimerDelayer(timeSpan);
|
||||
delayer.Action += new EventHandler<object>((object s, object arg) =>
|
||||
delayer.Action += (s, arg) =>
|
||||
{
|
||||
CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogVariableChanged("Slider", name);
|
||||
variableSliders.Remove(name);
|
||||
});
|
||||
};
|
||||
delayer.Start();
|
||||
variableSliders.Add(name, delayer);
|
||||
}
|
||||
|
@ -612,12 +605,8 @@ namespace CalculatorApp
|
|||
private EquationViewModel GetViewModelFromEquationTextBox(object sender)
|
||||
{
|
||||
var tb = (EquationTextBox)sender;
|
||||
if (tb == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var eq = (EquationViewModel)tb.DataContext;
|
||||
var eq = (EquationViewModel)tb?.DataContext;
|
||||
|
||||
return eq;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace CalculatorApp
|
|||
DependencyProperty.Register(nameof(SelectedColor), typeof(Windows.UI.Color), typeof(EquationStylePanelControl), new PropertyMetadata(Windows.UI.Colors.Black, (sender, args) =>
|
||||
{
|
||||
var self = (EquationStylePanelControl)sender;
|
||||
self.OnSelectedColorPropertyChanged((Windows.UI.Color)args.OldValue, (Windows.UI.Color)args.NewValue);
|
||||
self.OnSelectedColorPropertyChanged((Windows.UI.Color)args.NewValue);
|
||||
}));
|
||||
|
||||
public GraphControl.EquationLineStyle SelectedStyle
|
||||
|
@ -92,17 +92,14 @@ namespace CalculatorApp
|
|||
var lineStyle = ((EquationLineStyle?)line).Value;
|
||||
|
||||
var linePattern = new DoubleCollection();
|
||||
switch (lineStyle)
|
||||
if (lineStyle == EquationLineStyle.Dot)
|
||||
{
|
||||
case EquationLineStyle.Dot:
|
||||
linePattern.Add(1);
|
||||
break;
|
||||
case EquationLineStyle.Dash:
|
||||
linePattern.Add(2);
|
||||
linePattern.Add(1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
linePattern.Add(1);
|
||||
}
|
||||
else if (lineStyle == EquationLineStyle.Dash)
|
||||
{
|
||||
linePattern.Add(2);
|
||||
linePattern.Add(1);
|
||||
}
|
||||
|
||||
return linePattern;
|
||||
|
@ -230,20 +227,13 @@ namespace CalculatorApp
|
|||
if (e.AddedItems.Count > 0)
|
||||
{
|
||||
var brush = (e.AddedItems[0] as SolidColorBrush);
|
||||
if (brush == null)
|
||||
{
|
||||
SelectedColor = Colors.Black;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedColor = brush.Color;
|
||||
}
|
||||
SelectedColor = brush?.Color ?? Colors.Black;
|
||||
|
||||
CalculatorApp.ViewModel.Common.TraceLogger.GetInstance().LogGraphLineStyleChanged(LineStyleType.Color);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSelectedColorPropertyChanged(Color oldColor, Color newColor)
|
||||
private void OnSelectedColorPropertyChanged(Color newColor)
|
||||
{
|
||||
SelectColor(newColor);
|
||||
}
|
||||
|
@ -272,10 +262,8 @@ namespace CalculatorApp
|
|||
SelectedColorIndex = i;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
gridViewItem.IsSelected = false;
|
||||
}
|
||||
|
||||
gridViewItem.IsSelected = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,9 +281,8 @@ namespace CalculatorApp
|
|||
foreach (var item in StyleChooserBox.Items)
|
||||
{
|
||||
var style = ((EquationLineStyle)item);
|
||||
var comboBoxItem = (StyleChooserBox.ContainerFromItem(style) as ComboBoxItem);
|
||||
|
||||
if (comboBoxItem == null)
|
||||
if (!(StyleChooserBox.ContainerFromItem(style) is ComboBoxItem comboBoxItem))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -305,10 +292,8 @@ namespace CalculatorApp
|
|||
comboBoxItem.IsSelected = true;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
comboBoxItem.IsSelected = false;
|
||||
}
|
||||
|
||||
comboBoxItem.IsSelected = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -376,10 +376,7 @@ namespace CalculatorApp
|
|||
|
||||
var peer = FrameworkElementAutomationPeer.FromElement(TraceValue);
|
||||
|
||||
if (peer != null)
|
||||
{
|
||||
peer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
|
||||
}
|
||||
peer?.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
|
||||
|
||||
PositionGraphPopup();
|
||||
}
|
||||
|
@ -402,19 +399,16 @@ namespace CalculatorApp
|
|||
|
||||
try
|
||||
{
|
||||
string rawHtml;
|
||||
string equationHtml;
|
||||
|
||||
rawHtml = "<p><img src='graph.png' width='600' alt='" + resourceLoader.GetString("GraphImageAltText") + "'></p>";
|
||||
var rawHtml = "<p><img src='graph.png' width='600' alt='" + resourceLoader.GetString("GraphImageAltText") + "'></p>";
|
||||
|
||||
var equations = ViewModel.Equations;
|
||||
bool hasEquations = false;
|
||||
|
||||
if (equations.Count > 0)
|
||||
{
|
||||
equationHtml = "<span style=\"color: rgb(68, 114, 196); font-style: bold; font-size : 13pt;\">"
|
||||
+ resourceLoader.GetString("EquationsShareHeader") + "</span>"
|
||||
+ "<table cellpadding=\"0\" cellspacing=\"0\" >";
|
||||
var equationHtml = "<span style=\"color: rgb(68, 114, 196); font-style: bold; font-size : 13pt;\">"
|
||||
+ resourceLoader.GetString("EquationsShareHeader") + "</span>"
|
||||
+ "<table cellpadding=\"0\" cellspacing=\"0\" >";
|
||||
|
||||
foreach (var equation in equations)
|
||||
{
|
||||
|
@ -429,8 +423,7 @@ namespace CalculatorApp
|
|||
|
||||
expression = GraphingControl.ConvertToLinear(expression);
|
||||
|
||||
string equationColorHtml;
|
||||
equationColorHtml = "color:rgb(" + color.R.ToString() + "," + color.G.ToString() + "," + color.B.ToString() + ");";
|
||||
var equationColorHtml = "color:rgb(" + color.R + "," + color.G + "," + color.B + ");";
|
||||
|
||||
equationHtml += "<tr style=\"margin: 0pt 0pt 0pt 0pt; padding: 0pt 0pt 0pt 0pt; \"><td><span style=\"font-size: 22pt; line-height: 0;"
|
||||
+ equationColorHtml + "\">■</span></td><td><div style=\"margin: 4pt 0pt 0pt 6pt;\">"
|
||||
|
@ -518,7 +511,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,23 +527,13 @@ 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);
|
||||
var peer = FrameworkElementAutomationPeer.FromElement(GraphingControl);
|
||||
if (peer != null)
|
||||
{
|
||||
peer.RaiseNotificationEvent(announcement.Kind, announcement.Processing, announcement.Announcement, announcement.ActivityId);
|
||||
}
|
||||
peer?.RaiseNotificationEvent(announcement.Kind, announcement.Processing, announcement.Announcement, announcement.ActivityId);
|
||||
}
|
||||
|
||||
private void GraphingControl_GraphPlottedEvent(object sender, RoutedEventArgs e)
|
||||
|
@ -752,13 +735,13 @@ namespace CalculatorApp
|
|||
private void OnColorValuesChanged(UISettings sender, object args)
|
||||
{
|
||||
WeakReference weakThis = new WeakReference(this);
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
if (weakThis.Target is GraphingCalculator refThis && IsMatchAppTheme)
|
||||
{
|
||||
refThis.UpdateGraphTheme();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateGraphTheme()
|
||||
|
@ -788,13 +771,13 @@ namespace CalculatorApp
|
|||
|
||||
IsMatchAppTheme = isMatchAppTheme;
|
||||
WeakReference weakThis = new WeakReference(this);
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
_ = this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
if (weakThis.Target is GraphingCalculator refThis)
|
||||
{
|
||||
refThis.UpdateGraphTheme();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private const double zoomInScale = 1 / 1.0625;
|
||||
|
|
|
@ -103,11 +103,11 @@ namespace CalculatorApp
|
|||
{
|
||||
InverseHyperbolicTrigFunctions.Visibility = Visibility.Visible;
|
||||
}
|
||||
else if (isShiftChecked && !isHypeChecked)
|
||||
else if (isShiftChecked)
|
||||
{
|
||||
InverseTrigFunctions.Visibility = Visibility.Visible;
|
||||
}
|
||||
else if (!isShiftChecked && isHypeChecked)
|
||||
else if (isHypeChecked)
|
||||
{
|
||||
HyperbolicTrigFunctions.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ namespace CalculatorApp
|
|||
}
|
||||
}
|
||||
|
||||
private static readonly Dictionary<NumbersAndOperatorsEnum, Tuple<string, int, int>> buttonOutput = new Dictionary<NumbersAndOperatorsEnum, Tuple<string, int, int>>()
|
||||
private static readonly Dictionary<NumbersAndOperatorsEnum, Tuple<string, int, int>> buttonOutput = new Dictionary<NumbersAndOperatorsEnum, Tuple<string, int, int>>
|
||||
{
|
||||
{ NumbersAndOperatorsEnum.Sin, Tuple.Create("sin()", 4, 0) },
|
||||
{ NumbersAndOperatorsEnum.Cos, Tuple.Create("cos()", 4, 0) },
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace CalculatorApp
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
public CalculatorApp.ViewModel.GraphingSettingsViewModel ViewModel { get; set; }
|
||||
public CalculatorApp.ViewModel.GraphingSettingsViewModel ViewModel { get; }
|
||||
|
||||
public bool IsMatchAppTheme
|
||||
{
|
||||
|
@ -116,5 +116,5 @@ namespace CalculatorApp
|
|||
}
|
||||
|
||||
private bool m_IsMatchAppTheme;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ using Windows.UI.ViewManagement;
|
|||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Automation;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
|
@ -66,10 +65,7 @@ namespace CalculatorApp
|
|||
Window.Current.SizeChanged -= WindowSizeChanged;
|
||||
m_accessibilitySettings.HighContrastChanged -= OnHighContrastChanged;
|
||||
|
||||
if (m_calculator != null)
|
||||
{
|
||||
m_calculator.UnregisterEventHandlers();
|
||||
}
|
||||
m_calculator?.UnregisterEventHandlers();
|
||||
}
|
||||
|
||||
public void SetDefaultFocus()
|
||||
|
@ -206,58 +202,67 @@ namespace CalculatorApp
|
|||
|
||||
KeyboardShortcutManager.DisableShortcuts(false);
|
||||
|
||||
if (newValue == ViewMode.Standard)
|
||||
switch (newValue)
|
||||
{
|
||||
EnsureCalculator();
|
||||
Model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = true;
|
||||
m_calculator.AnimateCalculator(NavCategory.IsConverterViewMode(previousMode));
|
||||
Model.CalculatorViewModel.HistoryVM.ReloadHistory(newValue);
|
||||
}
|
||||
else if (newValue == ViewMode.Scientific)
|
||||
{
|
||||
EnsureCalculator();
|
||||
Model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = true;
|
||||
if (Model.PreviousMode != ViewMode.Scientific)
|
||||
{
|
||||
case ViewMode.Standard:
|
||||
EnsureCalculator();
|
||||
Model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = true;
|
||||
m_calculator.AnimateCalculator(NavCategory.IsConverterViewMode(previousMode));
|
||||
}
|
||||
Model.CalculatorViewModel.HistoryVM.ReloadHistory(newValue);
|
||||
break;
|
||||
case ViewMode.Scientific:
|
||||
{
|
||||
EnsureCalculator();
|
||||
Model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = true;
|
||||
if (Model.PreviousMode != ViewMode.Scientific)
|
||||
{
|
||||
m_calculator.AnimateCalculator(NavCategory.IsConverterViewMode(previousMode));
|
||||
}
|
||||
|
||||
Model.CalculatorViewModel.HistoryVM.ReloadHistory(newValue);
|
||||
}
|
||||
else if (newValue == ViewMode.Programmer)
|
||||
{
|
||||
Model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = false;
|
||||
EnsureCalculator();
|
||||
if (Model.PreviousMode != ViewMode.Programmer)
|
||||
{
|
||||
m_calculator.AnimateCalculator(NavCategory.IsConverterViewMode(previousMode));
|
||||
}
|
||||
}
|
||||
else if (NavCategory.IsDateCalculatorViewMode(newValue))
|
||||
{
|
||||
if (Model.CalculatorViewModel != null)
|
||||
{
|
||||
Model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = false;
|
||||
}
|
||||
EnsureDateCalculator();
|
||||
}
|
||||
else if (newValue == ViewMode.Graphing)
|
||||
{
|
||||
EnsureGraphingCalculator();
|
||||
KeyboardShortcutManager.DisableShortcuts(true);
|
||||
}
|
||||
else if (NavCategory.IsConverterViewMode(newValue))
|
||||
{
|
||||
if (Model.CalculatorViewModel != null)
|
||||
{
|
||||
Model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = false;
|
||||
}
|
||||
Model.CalculatorViewModel.HistoryVM.ReloadHistory(newValue);
|
||||
break;
|
||||
}
|
||||
case ViewMode.Programmer:
|
||||
{
|
||||
Model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = false;
|
||||
EnsureCalculator();
|
||||
if (Model.PreviousMode != ViewMode.Programmer)
|
||||
{
|
||||
m_calculator.AnimateCalculator(NavCategory.IsConverterViewMode(previousMode));
|
||||
}
|
||||
|
||||
EnsureConverter();
|
||||
if (!NavCategory.IsConverterViewMode(previousMode))
|
||||
{
|
||||
m_converter.AnimateConverter();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ViewMode.Graphing:
|
||||
EnsureGraphingCalculator();
|
||||
KeyboardShortcutManager.DisableShortcuts(true);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if (NavCategory.IsDateCalculatorViewMode(newValue))
|
||||
{
|
||||
if (Model.CalculatorViewModel != null)
|
||||
{
|
||||
Model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = false;
|
||||
}
|
||||
EnsureDateCalculator();
|
||||
}
|
||||
else if (NavCategory.IsConverterViewMode(newValue))
|
||||
{
|
||||
if (Model.CalculatorViewModel != null)
|
||||
{
|
||||
Model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = false;
|
||||
}
|
||||
|
||||
EnsureConverter();
|
||||
if (!NavCategory.IsConverterViewMode(previousMode))
|
||||
{
|
||||
m_converter.AnimateConverter();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ShowHideControls(newValue);
|
||||
|
@ -368,8 +373,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;
|
||||
}
|
||||
|
@ -435,10 +439,7 @@ namespace CalculatorApp
|
|||
|
||||
private void UpdatePanelViewState()
|
||||
{
|
||||
if (m_calculator != null)
|
||||
{
|
||||
m_calculator.UpdatePanelViewState();
|
||||
}
|
||||
m_calculator?.UpdatePanelViewState();
|
||||
}
|
||||
|
||||
private void OnHighContrastChanged(AccessibilitySettings sender, object args)
|
||||
|
@ -468,14 +469,14 @@ namespace CalculatorApp
|
|||
|
||||
// Delay load things later when we get a chance.
|
||||
_ = Dispatcher.RunAsync(
|
||||
CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
if (TraceLogger.GetInstance().IsWindowIdInLog(ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread())))
|
||||
{
|
||||
AppLifecycleLogger.GetInstance().LaunchUIResponsive();
|
||||
AppLifecycleLogger.GetInstance().LaunchVisibleComplete();
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void App_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
|
||||
|
@ -528,10 +529,7 @@ namespace CalculatorApp
|
|||
ShowHideControls(Model.Mode);
|
||||
}
|
||||
|
||||
if (m_dateCalculator != null)
|
||||
{
|
||||
m_dateCalculator.CloseCalendarFlyout();
|
||||
}
|
||||
m_dateCalculator?.CloseCalendarFlyout();
|
||||
}
|
||||
|
||||
private void EnsureDateCalculator()
|
||||
|
|
|
@ -60,28 +60,19 @@ namespace CalculatorApp
|
|||
private void OnClearMenuItemClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var memoryItem = GetMemoryItemForCurrentFlyout();
|
||||
if (memoryItem != null)
|
||||
{
|
||||
memoryItem.Clear();
|
||||
}
|
||||
memoryItem?.Clear();
|
||||
}
|
||||
|
||||
private void OnMemoryAddMenuItemClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var memoryItem = GetMemoryItemForCurrentFlyout();
|
||||
if (memoryItem != null)
|
||||
{
|
||||
memoryItem.MemoryAdd();
|
||||
}
|
||||
memoryItem?.MemoryAdd();
|
||||
}
|
||||
|
||||
private void OnMemorySubtractMenuItemClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var memoryItem = GetMemoryItemForCurrentFlyout();
|
||||
if (memoryItem != null)
|
||||
{
|
||||
memoryItem.MemorySubtract();
|
||||
}
|
||||
memoryItem?.MemorySubtract();
|
||||
}
|
||||
|
||||
private MemoryItemViewModel GetMemoryItemForCurrentFlyout()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
/* The AspectRatioTrigger class is a custom trigger for use with a VisualState. The trigger is designed to fire when the
|
||||
|
@ -18,7 +18,7 @@ namespace CalculatorApp.Views.StateTriggers
|
|||
{
|
||||
Height,
|
||||
Width
|
||||
};
|
||||
}
|
||||
|
||||
public sealed class AspectRatioTrigger : Windows.UI.Xaml.StateTriggerBase
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using CalculatorApp.ViewModel;
|
||||
using CalculatorApp.ViewModel;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -46,9 +46,6 @@ namespace CalculatorApp
|
|||
|
||||
public sealed class SupplementaryResultDataTemplateSelector : Windows.UI.Xaml.Controls.DataTemplateSelector
|
||||
{
|
||||
public SupplementaryResultDataTemplateSelector()
|
||||
{ }
|
||||
|
||||
public Windows.UI.Xaml.DataTemplate RegularTemplate { get; set; }
|
||||
|
||||
public Windows.UI.Xaml.DataTemplate DelighterTemplate { get; set; }
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace CalculatorApp
|
|||
{
|
||||
if (Frame.RequestedThemeProperty == dp)
|
||||
{
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => { SetTitleBarControlColors(); }));
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, SetTitleBarControlColors);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,8 +120,8 @@ namespace CalculatorApp
|
|||
return;
|
||||
}
|
||||
|
||||
double leftAddition = 0;
|
||||
double rightAddition = 0;
|
||||
double leftAddition;
|
||||
double rightAddition;
|
||||
|
||||
if (FlowDirection == FlowDirection.LeftToRight)
|
||||
{
|
||||
|
@ -140,18 +140,14 @@ namespace CalculatorApp
|
|||
|
||||
private void ColorValuesChanged(Windows.UI.ViewManagement.UISettings sender, object e)
|
||||
{
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => { SetTitleBarControlColors(); }));
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, SetTitleBarControlColors);
|
||||
}
|
||||
|
||||
private void SetTitleBarControlColors()
|
||||
{
|
||||
var applicationView = ApplicationView.GetForCurrentView();
|
||||
if (applicationView == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var applicationTitleBar = applicationView.TitleBar;
|
||||
var applicationTitleBar = applicationView?.TitleBar;
|
||||
if (applicationTitleBar == null)
|
||||
{
|
||||
return;
|
||||
|
@ -184,11 +180,11 @@ namespace CalculatorApp
|
|||
|
||||
private void OnHighContrastChanged(Windows.UI.ViewManagement.AccessibilitySettings sender, object args)
|
||||
{
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
SetTitleBarControlColors();
|
||||
SetTitleBarVisibility(false);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void OnWindowActivated(object sender, WindowActivatedEventArgs e)
|
||||
|
@ -281,12 +277,12 @@ namespace CalculatorApp
|
|||
public static readonly DependencyProperty BackButtonSpaceReservedProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(BackButtonSpaceReserved), typeof(bool), typeof(TitleBar),
|
||||
new PropertyMetadata(false, new PropertyChangedCallback((sender, args) =>
|
||||
new PropertyMetadata(false, (sender, args) =>
|
||||
{
|
||||
var self = sender as TitleBar;
|
||||
VisualStateManager.GoToState(
|
||||
self, (bool)args.NewValue ? self.BackButtonVisible.Name : self.BackButtonCollapsed.Name, true);
|
||||
})));
|
||||
}));
|
||||
|
||||
private readonly Windows.ApplicationModel.Core.CoreApplicationViewTitleBar m_coreTitleBar;
|
||||
private readonly Windows.UI.ViewManagement.UISettings m_uiSettings;
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace CalculatorApp
|
|||
|
||||
public void SetDefaultFocus()
|
||||
{
|
||||
Control[] focusPrecedence = new Control[] { Value1, CurrencyRefreshBlockControl, OfflineBlock, ClearEntryButtonPos0 };
|
||||
Control[] focusPrecedence = { Value1, CurrencyRefreshBlockControl, OfflineBlock, ClearEntryButtonPos0 };
|
||||
|
||||
foreach (Control control in focusPrecedence)
|
||||
{
|
||||
|
@ -368,10 +368,7 @@ namespace CalculatorApp
|
|||
|
||||
private void HideProgressRing()
|
||||
{
|
||||
if (m_delayTimer != null)
|
||||
{
|
||||
m_delayTimer.Stop();
|
||||
}
|
||||
m_delayTimer?.Stop();
|
||||
|
||||
CurrencyLoadingProgressRing.IsActive = false;
|
||||
}
|
||||
|
@ -391,8 +388,8 @@ namespace CalculatorApp
|
|||
private static readonly Lazy<UISettings> uiSettings = new Lazy<UISettings>(true);
|
||||
private readonly Windows.UI.Xaml.Controls.MenuFlyout m_resultsFlyout = default;
|
||||
|
||||
private readonly string m_chargesMayApplyText = string.Empty;
|
||||
private readonly string m_failedToRefreshText = string.Empty;
|
||||
private readonly string m_chargesMayApplyText;
|
||||
private readonly string m_failedToRefreshText;
|
||||
|
||||
private bool m_meteredConnectionOverride;
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace CalculatorApp
|
|||
public Task HandleViewRelease()
|
||||
{
|
||||
TaskCompletionSource<object> tsource = new TaskCompletionSource<object>();
|
||||
_ = m_coreDispatcher.RunAsync(CoreDispatcherPriority.Low, new DispatchedHandler(() =>
|
||||
_ = m_coreDispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
|
||||
{
|
||||
KeyboardShortcutManager.OnWindowClosed(this.m_viewId);
|
||||
Window.Current.Content = null;
|
||||
|
@ -70,7 +70,7 @@ namespace CalculatorApp
|
|||
tsource.SetResult(new object());
|
||||
this.m_coreDispatcher.StopProcessEvents();
|
||||
Window.Current.Close();
|
||||
}));
|
||||
});
|
||||
|
||||
return tsource.Task;
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ namespace CalculatorUITestFramework
|
|||
public string GetValue()
|
||||
{
|
||||
var equalSignIndex = Item.Text.IndexOf("=");
|
||||
return Item.Text.Substring(equalSignIndex + 1).Trim();
|
||||
return Item.Text[(equalSignIndex + 1)..].Trim();
|
||||
}
|
||||
public string GetExpression()
|
||||
{
|
||||
var equalSignIndex = Item.Text.IndexOf("=");
|
||||
return Item.Text.Substring(0, equalSignIndex + 1).Trim();
|
||||
return Item.Text[..(equalSignIndex + 1)].Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,63 +41,27 @@ namespace CalculatorUITestFramework
|
|||
/// <param name="mode">The mode to be changed to</param>
|
||||
public void ChangeCalculatorMode(CalculatorMode mode)
|
||||
{
|
||||
string modeAccessibilityId;
|
||||
switch (mode)
|
||||
string modeAccessibilityId = mode switch
|
||||
{
|
||||
case CalculatorMode.StandardCalculator:
|
||||
modeAccessibilityId = "Standard";
|
||||
break;
|
||||
case CalculatorMode.ScientificCalculator:
|
||||
modeAccessibilityId = "Scientific";
|
||||
break;
|
||||
case CalculatorMode.ProgrammerCalculator:
|
||||
modeAccessibilityId = "Programmer";
|
||||
break;
|
||||
case CalculatorMode.DateCalculator:
|
||||
modeAccessibilityId = "Date";
|
||||
break;
|
||||
case CalculatorMode.Currency:
|
||||
modeAccessibilityId = "Currency";
|
||||
break;
|
||||
case CalculatorMode.Volume:
|
||||
modeAccessibilityId = "Volume";
|
||||
break;
|
||||
case CalculatorMode.Length:
|
||||
modeAccessibilityId = "Length";
|
||||
break;
|
||||
case CalculatorMode.Weight:
|
||||
modeAccessibilityId = "Weight";
|
||||
break;
|
||||
case CalculatorMode.Temperature:
|
||||
modeAccessibilityId = "Temperature";
|
||||
break;
|
||||
case CalculatorMode.Energy:
|
||||
modeAccessibilityId = "Energy";
|
||||
break;
|
||||
case CalculatorMode.Area:
|
||||
modeAccessibilityId = "Area";
|
||||
break;
|
||||
case CalculatorMode.Speed:
|
||||
modeAccessibilityId = "Speed";
|
||||
break;
|
||||
case CalculatorMode.Time:
|
||||
modeAccessibilityId = "Time";
|
||||
break;
|
||||
case CalculatorMode.Power:
|
||||
modeAccessibilityId = "Power";
|
||||
break;
|
||||
case CalculatorMode.Data:
|
||||
modeAccessibilityId = "Data";
|
||||
break;
|
||||
case CalculatorMode.Pressure:
|
||||
modeAccessibilityId = "Pressure";
|
||||
break;
|
||||
case CalculatorMode.Angle:
|
||||
modeAccessibilityId = "Angle";
|
||||
break;
|
||||
default:
|
||||
throw (new ArgumentException("The mode is not valid"));
|
||||
}
|
||||
CalculatorMode.StandardCalculator => "Standard",
|
||||
CalculatorMode.ScientificCalculator => "Scientific",
|
||||
CalculatorMode.ProgrammerCalculator => "Programmer",
|
||||
CalculatorMode.DateCalculator => "Date",
|
||||
CalculatorMode.Currency => "Currency",
|
||||
CalculatorMode.Volume => "Volume",
|
||||
CalculatorMode.Length => "Length",
|
||||
CalculatorMode.Weight => "Weight",
|
||||
CalculatorMode.Temperature => "Temperature",
|
||||
CalculatorMode.Energy => "Energy",
|
||||
CalculatorMode.Area => "Area",
|
||||
CalculatorMode.Speed => "Speed",
|
||||
CalculatorMode.Time => "Time",
|
||||
CalculatorMode.Power => "Power",
|
||||
CalculatorMode.Data => "Data",
|
||||
CalculatorMode.Pressure => "Pressure",
|
||||
CalculatorMode.Angle => "Angle",
|
||||
_ => throw (new ArgumentException("The mode is not valid"))
|
||||
};
|
||||
|
||||
this.NavigationMenuButton.Click();
|
||||
this.NavigationMenuPane.WaitForDisplayed();
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace CalculatorUITestFramework
|
|||
string numberStr = number.ToString(CultureInfo.InvariantCulture);
|
||||
if (numberStr.StartsWith("-"))
|
||||
{
|
||||
numberStr = numberStr.Substring(1) + "-";
|
||||
numberStr = numberStr[1..] + "-";
|
||||
}
|
||||
foreach (char digit in numberStr)
|
||||
{
|
||||
|
@ -77,7 +77,7 @@ namespace CalculatorUITestFramework
|
|||
this.NegateButton.Click();
|
||||
break;
|
||||
default:
|
||||
throw (new ArgumentException(string.Format("{0} is not valid", digit)));
|
||||
throw (new ArgumentException($"{digit} is not valid"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,21 +109,13 @@ namespace CalculatorUITestFramework
|
|||
public void SetAngleOperator(AngleOperatorState value)
|
||||
{
|
||||
//set the desired string value for the button
|
||||
string desiredId;
|
||||
switch (value)
|
||||
string desiredId = value switch
|
||||
{
|
||||
case AngleOperatorState.Degrees:
|
||||
desiredId = "degButton";
|
||||
break;
|
||||
case AngleOperatorState.Gradians:
|
||||
desiredId = "gradButton";
|
||||
break;
|
||||
case AngleOperatorState.Radians:
|
||||
desiredId = "radButton";
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
AngleOperatorState.Degrees => "degButton",
|
||||
AngleOperatorState.Gradians => "gradButton",
|
||||
AngleOperatorState.Radians => "radButton",
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
while (this.DegRadGradButton.GetAttribute("AutomationId") != desiredId)
|
||||
{
|
||||
this.DegRadGradButton.Click();
|
||||
|
|
|
@ -16,18 +16,7 @@ namespace CalculatorUITestFramework
|
|||
public MemoryPanel MemoryPanel = new MemoryPanel();
|
||||
private const string defaultAppId = "Microsoft.WindowsCalculator.Dev_8wekyb3d8bbwe!App";
|
||||
private static WinAppDriver instance = null;
|
||||
public static WinAppDriver Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new WinAppDriver();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
public static WinAppDriver Instance => instance ??= new WinAppDriver();
|
||||
|
||||
public WindowsDriver<WindowsElement> CalculatorSession { get; private set; }
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@ namespace CalculatorUITestFramework
|
|||
this.Service.StartInfo.RedirectStandardOutput = true;
|
||||
this.Service.OutputDataReceived += (sender, e) => OutputDataReceived?.Invoke(this, e);
|
||||
|
||||
bool isLaunched = false;
|
||||
string msgTxt =
|
||||
$"The local WinAppDriver server has not been started: {this.FileName.FullName} Arguments: {this.Arguments}. " +
|
||||
"\n";
|
||||
|
@ -81,7 +80,7 @@ namespace CalculatorUITestFramework
|
|||
throw new Exception(msgTxt, e);
|
||||
}
|
||||
|
||||
isLaunched = Ping();
|
||||
bool isLaunched = Ping();
|
||||
if (!isLaunched)
|
||||
{
|
||||
DestroyProcess();
|
||||
|
@ -91,7 +90,7 @@ namespace CalculatorUITestFramework
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsRunning
|
||||
private bool IsRunning
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -134,6 +133,7 @@ namespace CalculatorUITestFramework
|
|||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -39,16 +39,12 @@ namespace CalculatorUITestFramework
|
|||
|
||||
public WindowsDriverServiceBuilder WithFileInfo(FileInfo fileInfo)
|
||||
{
|
||||
this.FileInfo = fileInfo ?? throw new ArgumentNullException("FileInfo should not be NULL");
|
||||
this.FileInfo = fileInfo ?? throw new ArgumentNullException("FileInfo should not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
public WindowsDriverServiceBuilder WithStartUpTimeOut(TimeSpan startUpTimeout)
|
||||
{
|
||||
if (startUpTimeout == null)
|
||||
{
|
||||
throw new ArgumentNullException("A startup timeout should not be NULL");
|
||||
}
|
||||
this.StartUpTimeout = startUpTimeout;
|
||||
return this;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue