mirror of
https://github.com/Microsoft/calculator.git
synced 2025-07-16 02:02:51 -07:00
Hello C# - Migrating the codebase from C++/CX to C# (Phase 1) (#1598)
* Hello C# - Going to an official feature branch (#1544) * change CalcViewModel into a WindowsRuntimeComponent project (#5) * change CalcViewModel into a WindowsRuntimeComponent project * remove the old UI codebase (#6) * initially migrated C# codebase by tian (#7) * initial migrated C# codebase by tian * format the codebase * resolve comments * undo: modifications on UI test project * Remove the blocks that have more than 1 empty line. * Register DP using keyword 'nameof' * C# Migration: Initially migrated C# codebase by Han (#8) * C# Migration: Initially migrated C# codebase by Han * Resolved comments and misssing asset * Added three files to Calculator project * Added TODO comment and updated Object * NavCategory: temporary resolution of the hang issue (#9) * Updated CalcViewModel and missing files (#10) * Updated CalcViewModel and WinMeta * Added Calculator.rc * Resolved comment for InitializeLocalizationSettings * add: views/unitconverter.xaml (#11) * add: views/unitconverter.xaml * format the code * remove the extra empty line * add an empty line * check null before invoking event handlers (#12) * fix problems of the migration of OBSERVABLE_PROPERTY_RW (#13) * fixes crash in MathRichEditBox.ctor() (#14) * fixes crash in MathRichEditBox.ctor() * typo * Update azure-pipelines.ci.yaml for Azure Pipelines * Added a link copy of CalcViewModel to temporarily pass Unit Tests (#16) * Updated CalcViewModelCopyForUT configuration (#17) * changes output path of the UI project to align with other projects (#15) * fixes EETypeLoadException issue: export class DelegateCommand (#18) * fixes EETypeLoadException issue: export class DelegateCommand * weak-reference in C++/CX * WeakRef in C# codebase * UTF-8-BOM * spaces in macro * resolve some comments from the offline review * format * rename file * fixes the memory list issue (#20) * fixes a wrongly migrated property * UTF-8-BOM * fixes up the crash of type casting (#21) * Update localized strings 2021-01-04 (#1458) (#23) (cherry picked from commitcdcb95656d
) Co-authored-by: Matt Cooley <macool@microsoft.com> * Fixup tests (#1429) (#24) - Removed unneeded "ToString" calls - Fixed typos - Renamed "fEButtonState" to "FEButtonState" (cherry picked from commit66ad328d00
) Co-authored-by: N <71219152+PokeCodec@users.noreply.github.com> * Update graph internal engine verseion (#1466) (#25) (cherry picked from commit0048dcb500
) Co-authored-by: Quentin Al-Timimi <27322516+quentin987@users.noreply.github.com> * Turn off DFS file shares in internal build system (#1470) (#26) (cherry picked from commit885fa23a89
) Co-authored-by: Matt Cooley <macool@microsoft.com> * Improve clarity of math expressions in history for Standard Calculator (feature #138) (#1453) (#27) * Implemented feature & added unit tests * Fixed more unit/ui tests * Refactored tests * Update HistoryTests.cpp * Update HistoryTests.cpp * Update HistoryTests.cpp * Update HistoryTests.cpp * Update HistoryTests.cpp * Update HistoryTests.cpp * Update HistoryTests.cpp * Update HistoryTests.cpp (cherry picked from commit565e3e2714
) Co-authored-by: Wei (Waley) Zhang <waley.zhang@microsoft.com> * Adds unit-test cases for NarratorAnnouncement after fixing issue #1386 (#1469) (#28) * fix bug: No confirmation is announced by the narrator after activating 'Remove equation' button #1386 * Unit Test: Add NarratorAnnouncementUnitTests Co-authored-by: tain <tankle_@hotmail.com> (cherry picked from commit9d8e2ad18c
) Co-authored-by: Tian L <60599517+MSFT-Tilia@users.noreply.github.com> * Move localization pipeline sync schedule to the YAML file (#1478) (#30) (cherry picked from commit007eccd940
) Co-authored-by: Matt Cooley <macool@microsoft.com> * remove the strong reference carried from delegate (#32) * Remove the finalizer of ControlSizeTrigger (#31) * Normalize the namespace of CalcViewModel (#33) * ViewMode: arrange namespaces * UI build pass * run release * UT build pass * pass build * resolve comment: make the diff results cleaner * resolve comment: make the diff results cleaner (2) * resolve comment: make the diff results cleaner (3) * resolve comment: move impl into a namespace * update: spaces * update: CalculatorButtonUser.h * UTF-8 to UTF-8-BOM * remove ViewState.h/.cpp from CalcViewModel path * revert changes for NavCategory.cpp * remove extra space * remove UCM * remove BOM * Fixed a graphing calculator "permissions" bug caused by PR #1426 (#1471) (#34) - The PR #1426 can cause a crash when no users are returned via `User::FindAllAsync(UserType::LocalUser)` when subsequently trying to access the first user. The existing code also does not guarantee that the returned user is the currently active user. - This fix retrieves the user that opened the app and passes this user into a function to check if this user has the proper permissions to access the graphing mode. This makes sense since the active user is indistinguishable (at least from the app's perspective) to the user who opened the app. This user's permissions are then propagated downwards to properly set up the navigation menu of the app. - Implementation detail worth pointing out: `s_categoryManifest` is what is used to populate the navigation menu of the app, but this variable is static by design, so a separate function was written to override the appropriate `isEnabled` value in `s_categoryManifest`. This function is called by `onLaunched`. - Manual testing Co-authored-by: Wei (Waley) Zhang <waley.zhang@microsoft.com> * fixes up a bug (#35) * fix csproj (#37) Co-authored-by: hanzhang54 <zhangh@microsoft.com> Co-authored-by: Matt Cooley <macool@microsoft.com> Co-authored-by: N <71219152+PokeCodec@users.noreply.github.com> Co-authored-by: Quentin Al-Timimi <27322516+quentin987@users.noreply.github.com> Co-authored-by: Wei (Waley) Zhang <waley.zhang@microsoft.com> Co-authored-by: Tian L <60599517+MSFT-Tilia@users.noreply.github.com> * **BYPASS_SECRET_SCANNING** (#1546) * Fixes a bug about the UI of expression tokens (#1547) * fix * [FeatureBranch] Fixes x86/ARM/ARM64 builds for the CI-Pipeline (#1550) * **BYPASS_SECRET_SCANNING** * fix * fixes x86/ARM/ARM64 builds for CI-Pipeline * Add headers missing for compilation with GCC (#1468) (#1551) Things that required such update included: * `wstringstream` * `setprecision` * `SCODE_CODE`, `E_BOUNDS` * Various SAL macros Co-authored-by: Michał Janiszewski <janisozaur@users.noreply.github.com> * Update nuget.config file (#1486) (#1552) Co-authored-by: Matt Cooley <macool@microsoft.com> * Fixes up some simple miscellaneous TODO items (#1556) * #DEBUG is a known C# preprocessor directive * So far, we haven't observed the problem described in the comment from C# async * fixes misc TODO items * resolve some warnings (#1564) * Add internal CI pipeline (#1553) (#1565) * Add CI-internal pipeline * No ARM64, to match release Co-authored-by: Matt Cooley <macool@microsoft.com> * Temporarily disable PGO NuGet package (#1510) (#1566) Co-authored-by: Matt Cooley <macool@microsoft.com> * [C# Calc]Removes WinMeta.cs (#1567) * remove WinMeta.cs * undo a trivial change * UTF-8 BOM * [C# Calc] Reverts some changes for Currency constants (#1570) * Update2108release - experimental (#1572) * adjusts Calculator.csproj (#1571) * fixes BinSkim problems (#1573) * fixes an issue around line style (#1575) * fixes the missed NULLs (#1576) (#1578) * Fix the Missing Part in Unit Converter Constructor (#1579) * fixes: calculator doesn't remember its previous mode (#1580) * Fixes: GraphingNumber doesn't work correctly (#1585) * fixes: GraphingNumber doesn't work correctly * Avoid crashing * fixes binding (#1586) * resolve TODO items (#1589) * Improving keyboard support in VariableValueSlider (#1559) (#1595) Co-authored-by: Dave Grochocki <grochocki@users.noreply.github.com> * [C# Calc] Fixes: Keep the value away from getting rounded in Graphing Mode (#1596) * keep the value away from getting rounded * set the display precision to 6 to align with C++ impl * fixes the button-light-up time (#1597) * fixes up merging flaws * Update2108release * fixes (#1599) * keep master for ci pipeline * remove the Resources filter from CalcViewModel project * removes `that` since `this` can be captured automatically * AppxBundlePlatforms * StampAssemblyInfo * removes PreferredToolArchitecture * Change the arg AppVersion into Version * Change the arg AppVersion into Version * from Calculator.rc to AssemblyInfo.cs * Adds assembly-info Co-authored-by: hanzhang54 <zhangh@microsoft.com> Co-authored-by: Matt Cooley <macool@microsoft.com> Co-authored-by: N <71219152+PokeCodec@users.noreply.github.com> Co-authored-by: Quentin Al-Timimi <27322516+quentin987@users.noreply.github.com> Co-authored-by: Wei (Waley) Zhang <waley.zhang@microsoft.com> Co-authored-by: Tian L <60599517+MSFT-Tilia@users.noreply.github.com> Co-authored-by: Michał Janiszewski <janisozaur@users.noreply.github.com> Co-authored-by: Dave Grochocki <grochocki@users.noreply.github.com>
This commit is contained in:
parent
233339d289
commit
fdae1000fc
300 changed files with 14563 additions and 16717 deletions
573
src/Calculator/Views/MainPage.xaml.cs
Normal file
573
src/Calculator/Views/MainPage.xaml.cs
Normal file
|
@ -0,0 +1,573 @@
|
|||
using CalculatorApp.Common;
|
||||
using CalculatorApp.Converters;
|
||||
using CalculatorApp.ViewModel;
|
||||
using CalculatorApp.ViewModel.Common;
|
||||
using CalculatorApp.ViewModel.Common.Automation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.Graphics.Display;
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Core;
|
||||
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.Input;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using MUXC = Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainPage : Page
|
||||
{
|
||||
public MainPage()
|
||||
{
|
||||
m_model = new ViewModel.ApplicationViewModel();
|
||||
InitializeComponent();
|
||||
|
||||
KeyboardShortcutManager.Initialize();
|
||||
|
||||
Application.Current.Suspending += App_Suspending;
|
||||
m_model.PropertyChanged += OnAppPropertyChanged;
|
||||
m_accessibilitySettings = new AccessibilitySettings();
|
||||
|
||||
if(Utilities.GetIntegratedDisplaySize(out var sizeInInches))
|
||||
{
|
||||
if(sizeInInches < 7.0) // If device's display size (diagonal length) is less than 7 inches then keep the calc always in Portrait mode only
|
||||
{
|
||||
DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait | DisplayOrientations.PortraitFlipped;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CalculatorApp.ViewModel.ApplicationViewModel Model
|
||||
{
|
||||
get => m_model;
|
||||
}
|
||||
|
||||
public void UnregisterEventHandlers()
|
||||
{
|
||||
Window.Current.SizeChanged -= WindowSizeChanged;
|
||||
m_accessibilitySettings.HighContrastChanged -= OnHighContrastChanged;
|
||||
|
||||
if (m_calculator != null)
|
||||
{
|
||||
m_calculator.UnregisterEventHandlers();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDefaultFocus()
|
||||
{
|
||||
if (m_calculator != null && m_calculator.Visibility == Visibility.Visible)
|
||||
{
|
||||
m_calculator.SetDefaultFocus();
|
||||
}
|
||||
if (m_dateCalculator != null && m_dateCalculator.Visibility == Visibility.Visible)
|
||||
{
|
||||
m_dateCalculator.SetDefaultFocus();
|
||||
}
|
||||
if (m_graphingCalculator != null && m_graphingCalculator.Visibility == Visibility.Visible)
|
||||
{
|
||||
m_graphingCalculator.SetDefaultFocus();
|
||||
}
|
||||
if (m_converter != null && m_converter.Visibility == Visibility.Visible)
|
||||
{
|
||||
m_converter.SetDefaultFocus();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHeaderAutomationName()
|
||||
{
|
||||
ViewMode mode = m_model.Mode;
|
||||
var resProvider = AppResourceProvider.GetInstance();
|
||||
|
||||
string name;
|
||||
if (NavCategory.IsDateCalculatorViewMode(mode))
|
||||
{
|
||||
name = resProvider.GetResourceString("HeaderAutomationName_Date");
|
||||
}
|
||||
else
|
||||
{
|
||||
string full = string.Empty;
|
||||
if (NavCategory.IsCalculatorViewMode(mode) || NavCategory.IsGraphingCalculatorViewMode(mode))
|
||||
{
|
||||
full = resProvider.GetResourceString("HeaderAutomationName_Calculator");
|
||||
}
|
||||
else if (NavCategory.IsConverterViewMode(mode))
|
||||
{
|
||||
full = resProvider.GetResourceString("HeaderAutomationName_Converter");
|
||||
}
|
||||
name = LocalizationStringUtil.GetLocalizedString(full, m_model.CategoryName);
|
||||
}
|
||||
|
||||
AutomationProperties.SetName(Header, name);
|
||||
}
|
||||
|
||||
public ObservableCollection<object> CreateUIElementsForCategories(IObservableVector<NavCategoryGroup> categories)
|
||||
{
|
||||
var menuCategories = new ObservableCollection<object>();
|
||||
|
||||
foreach (var group in categories)
|
||||
{
|
||||
menuCategories.Add(CreateNavViewHeaderFromGroup(group));
|
||||
|
||||
foreach (var category in group.Categories)
|
||||
{
|
||||
menuCategories.Add(CreateNavViewItemFromCategory(category));
|
||||
}
|
||||
}
|
||||
|
||||
return menuCategories;
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
ViewMode initialMode = ViewMode.Standard;
|
||||
|
||||
string stringParameter = (e.Parameter as string);
|
||||
if (!string.IsNullOrEmpty(stringParameter))
|
||||
{
|
||||
initialMode = (ViewMode)Convert.ToInt32(stringParameter);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
|
||||
if (localSettings.Values.ContainsKey(ApplicationViewModel.ModePropertyName))
|
||||
{
|
||||
initialMode = NavCategory.Deserialize(localSettings.Values[ApplicationViewModel.ModePropertyName]);
|
||||
}
|
||||
}
|
||||
|
||||
m_model.Initialize(initialMode);
|
||||
}
|
||||
|
||||
private void WindowSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
|
||||
{
|
||||
// We don't use layout aware page's view states, we have our own
|
||||
UpdateViewState();
|
||||
}
|
||||
|
||||
private void OnAppPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
string propertyName = e.PropertyName;
|
||||
if (propertyName == ApplicationViewModel.ModePropertyName)
|
||||
{
|
||||
ViewMode newValue = m_model.Mode;
|
||||
ViewMode previousMode = m_model.PreviousMode;
|
||||
|
||||
KeyboardShortcutManager.DisableShortcuts(false);
|
||||
|
||||
if (newValue == ViewMode.Standard)
|
||||
{
|
||||
EnsureCalculator();
|
||||
m_model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = true;
|
||||
m_calculator.AnimateCalculator(NavCategory.IsConverterViewMode(previousMode));
|
||||
m_model.CalculatorViewModel.HistoryVM.ReloadHistory(newValue);
|
||||
}
|
||||
else if (newValue == ViewMode.Scientific)
|
||||
{
|
||||
EnsureCalculator();
|
||||
m_model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = true;
|
||||
if (m_model.PreviousMode != ViewMode.Scientific)
|
||||
{
|
||||
m_calculator.AnimateCalculator(NavCategory.IsConverterViewMode(previousMode));
|
||||
}
|
||||
|
||||
m_model.CalculatorViewModel.HistoryVM.ReloadHistory(newValue);
|
||||
}
|
||||
else if (newValue == ViewMode.Programmer)
|
||||
{
|
||||
m_model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = false;
|
||||
EnsureCalculator();
|
||||
if (m_model.PreviousMode != ViewMode.Programmer)
|
||||
{
|
||||
m_calculator.AnimateCalculator(NavCategory.IsConverterViewMode(previousMode));
|
||||
}
|
||||
}
|
||||
else if (NavCategory.IsDateCalculatorViewMode(newValue))
|
||||
{
|
||||
if (m_model.CalculatorViewModel != null)
|
||||
{
|
||||
m_model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = false;
|
||||
}
|
||||
EnsureDateCalculator();
|
||||
}
|
||||
else if (newValue == ViewMode.Graphing)
|
||||
{
|
||||
EnsureGraphingCalculator();
|
||||
KeyboardShortcutManager.DisableShortcuts(true);
|
||||
}
|
||||
else if (NavCategory.IsConverterViewMode(newValue))
|
||||
{
|
||||
if (m_model.CalculatorViewModel != null)
|
||||
{
|
||||
m_model.CalculatorViewModel.HistoryVM.AreHistoryShortcutsEnabled = false;
|
||||
}
|
||||
|
||||
EnsureConverter();
|
||||
if (!NavCategory.IsConverterViewMode(previousMode))
|
||||
{
|
||||
m_converter.AnimateConverter();
|
||||
}
|
||||
}
|
||||
|
||||
ShowHideControls(newValue);
|
||||
|
||||
UpdateViewState();
|
||||
SetDefaultFocus();
|
||||
}
|
||||
else if (propertyName == ApplicationViewModel.CategoryNamePropertyName)
|
||||
{
|
||||
SetHeaderAutomationName();
|
||||
AnnounceCategoryName();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNavLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (NavView.SelectedItem == null)
|
||||
{
|
||||
var menuItems = ((ObservableCollection<object>)NavView.MenuItemsSource);
|
||||
var itemCount = ((int)menuItems.Count);
|
||||
var flatIndex = NavCategory.GetFlatIndex(Model.Mode);
|
||||
|
||||
if (flatIndex >= 0 && flatIndex < itemCount)
|
||||
{
|
||||
NavView.SelectedItem = menuItems[flatIndex];
|
||||
}
|
||||
}
|
||||
|
||||
var acceleratorList = new List<MyVirtualKey>();
|
||||
NavCategory.GetCategoryAcceleratorKeys(acceleratorList);
|
||||
|
||||
foreach (var accelerator in acceleratorList)
|
||||
{
|
||||
NavView.SetValue(KeyboardShortcutManager.VirtualKeyAltChordProperty, accelerator);
|
||||
}
|
||||
// Special case logic for Ctrl+E accelerator for Date Calculation Mode
|
||||
NavView.SetValue(KeyboardShortcutManager.VirtualKeyControlChordProperty, MyVirtualKey.E);
|
||||
}
|
||||
|
||||
private void OnNavPaneOpening(MUXC.NavigationView sender, object args)
|
||||
{
|
||||
if (AboutButton != null)
|
||||
{
|
||||
FindName("AboutButton");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNavPaneOpened(MUXC.NavigationView sender, object args)
|
||||
{
|
||||
KeyboardShortcutManager.HonorShortcuts(false);
|
||||
TraceLogger.GetInstance().LogNavBarOpened();
|
||||
}
|
||||
|
||||
private void OnNavPaneClosed(MUXC.NavigationView sender, object args)
|
||||
{
|
||||
if (Model.Mode != ViewMode.Graphing)
|
||||
{
|
||||
KeyboardShortcutManager.HonorShortcuts(true);
|
||||
}
|
||||
|
||||
SetDefaultFocus();
|
||||
}
|
||||
|
||||
private void OnNavSelectionChanged(object sender, MUXC.NavigationViewSelectionChangedEventArgs e)
|
||||
{
|
||||
var item = (e.SelectedItemContainer as MUXC.NavigationViewItem);
|
||||
if (item != null)
|
||||
{
|
||||
var selectedItem = ((NavCategory)item.DataContext);
|
||||
Model.Mode = selectedItem.Mode;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNavItemInvoked(MUXC.NavigationView sender, MUXC.NavigationViewItemInvokedEventArgs e)
|
||||
{
|
||||
NavView.IsPaneOpen = false;
|
||||
}
|
||||
|
||||
private void OnAboutButtonClick(object sender, TappedRoutedEventArgs e)
|
||||
{
|
||||
ShowAboutPage();
|
||||
}
|
||||
|
||||
private void OnAboutButtonKeyDown(object sender, KeyRoutedEventArgs e)
|
||||
{
|
||||
if (e.Key == Windows.System.VirtualKey.Space || e.Key == Windows.System.VirtualKey.Enter)
|
||||
{
|
||||
ShowAboutPage();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAboutFlyoutOpened(object sender, object e)
|
||||
{
|
||||
// Keep Ignoring Escape till the About page flyout is opened
|
||||
KeyboardShortcutManager.IgnoreEscape(false);
|
||||
KeyboardShortcutManager.HonorShortcuts(false);
|
||||
}
|
||||
|
||||
private void OnAboutFlyoutClosed(object sender, object e)
|
||||
{
|
||||
// Start Honoring Escape once the About page flyout is closed
|
||||
KeyboardShortcutManager.HonorEscape();
|
||||
KeyboardShortcutManager.HonorShortcuts(!NavView.IsPaneOpen);
|
||||
}
|
||||
|
||||
private void AlwaysOnTopButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Model.ToggleAlwaysOnTop(0, 0);
|
||||
}
|
||||
|
||||
private void TitleBarAlwaysOnTopButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var bounds = Window.Current.Bounds;
|
||||
Model.ToggleAlwaysOnTop((float)bounds.Width, (float)bounds.Height);
|
||||
}
|
||||
|
||||
private MUXC.NavigationViewItemHeader CreateNavViewHeaderFromGroup(NavCategoryGroup group)
|
||||
{
|
||||
var header = new MUXC.NavigationViewItemHeader();
|
||||
header.DataContext = group;
|
||||
|
||||
header.Content = group.Name;
|
||||
AutomationProperties.SetName(header, group.AutomationName);
|
||||
AutomationProperties.SetHeadingLevel(header, Windows.UI.Xaml.Automation.Peers.AutomationHeadingLevel.Level1);
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
private MUXC.NavigationViewItem CreateNavViewItemFromCategory(NavCategory category)
|
||||
{
|
||||
var item = new MUXC.NavigationViewItem();
|
||||
item.DataContext = category;
|
||||
|
||||
var icon = new FontIcon();
|
||||
icon.FontFamily = (Windows.UI.Xaml.Media.FontFamily)(App.Current.Resources["CalculatorFontFamily"]);
|
||||
icon.Glyph = category.Glyph;
|
||||
item.Icon = icon;
|
||||
|
||||
item.Content = category.Name;
|
||||
item.AccessKey = category.AccessKey;
|
||||
item.IsEnabled = category.IsEnabled;
|
||||
item.Style = (Windows.UI.Xaml.Style)(Resources["NavViewItemStyle"]);
|
||||
|
||||
AutomationProperties.SetName(item, category.AutomationName);
|
||||
AutomationProperties.SetAutomationId(item, category.AutomationId);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
private void ShowHideControls(ViewMode mode)
|
||||
{
|
||||
var isCalcViewMode = NavCategory.IsCalculatorViewMode(mode);
|
||||
var isDateCalcViewMode = NavCategory.IsDateCalculatorViewMode(mode);
|
||||
var isGraphingCalcViewMode = NavCategory.IsGraphingCalculatorViewMode(mode);
|
||||
var isConverterViewMode = NavCategory.IsConverterViewMode(mode);
|
||||
|
||||
if (m_calculator != null)
|
||||
{
|
||||
m_calculator.Visibility = BooleanToVisibilityConverter.Convert(isCalcViewMode);
|
||||
m_calculator.IsEnabled = isCalcViewMode;
|
||||
}
|
||||
|
||||
if (m_dateCalculator != null)
|
||||
{
|
||||
m_dateCalculator.Visibility = BooleanToVisibilityConverter.Convert(isDateCalcViewMode);
|
||||
m_dateCalculator.IsEnabled = isDateCalcViewMode;
|
||||
}
|
||||
|
||||
if (m_graphingCalculator != null)
|
||||
{
|
||||
m_graphingCalculator.Visibility = BooleanToVisibilityConverter.Convert(isGraphingCalcViewMode);
|
||||
m_graphingCalculator.IsEnabled = isGraphingCalcViewMode;
|
||||
}
|
||||
|
||||
if (m_converter != null)
|
||||
{
|
||||
m_converter.Visibility = BooleanToVisibilityConverter.Convert(isConverterViewMode);
|
||||
m_converter.IsEnabled = isConverterViewMode;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateViewState()
|
||||
{
|
||||
// All layout related view states are now handled only inside individual controls (standard, scientific, programmer, date, converter)
|
||||
if (NavCategory.IsConverterViewMode(m_model.Mode))
|
||||
{
|
||||
int modeIndex = NavCategory.GetIndexInGroup(m_model.Mode, CategoryGroupType.Converter);
|
||||
m_model.ConverterViewModel.CurrentCategory = m_model.ConverterViewModel.Categories[modeIndex];
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePanelViewState()
|
||||
{
|
||||
if (m_calculator != null)
|
||||
{
|
||||
m_calculator.UpdatePanelViewState();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnHighContrastChanged(AccessibilitySettings sender, object args)
|
||||
{
|
||||
if (Model.IsAlwaysOnTop && ActualHeight < 394)
|
||||
{
|
||||
// Sets to default always-on-top size to force re-layout
|
||||
ApplicationView.GetForCurrentView().TryResizeView(new Size(320, 394));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageLoaded(object sender, RoutedEventArgs args)
|
||||
{
|
||||
if (m_converter == null && m_calculator == null && m_dateCalculator == null && m_graphingCalculator == null)
|
||||
{
|
||||
// We have just launched into our default mode (standard calc) so ensure calc is loaded
|
||||
EnsureCalculator();
|
||||
m_model.CalculatorViewModel.IsStandard = true;
|
||||
}
|
||||
|
||||
Window.Current.SizeChanged += WindowSizeChanged;
|
||||
m_accessibilitySettings.HighContrastChanged += OnHighContrastChanged;
|
||||
UpdateViewState();
|
||||
|
||||
SetHeaderAutomationName();
|
||||
SetDefaultFocus();
|
||||
|
||||
// Delay load things later when we get a chance.
|
||||
_ = Dispatcher.RunAsync(
|
||||
CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
|
||||
{
|
||||
if (TraceLogger.GetInstance().IsWindowIdInLog(ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread())))
|
||||
{
|
||||
AppLifecycleLogger.GetInstance().LaunchUIResponsive();
|
||||
AppLifecycleLogger.GetInstance().LaunchVisibleComplete();
|
||||
}
|
||||
|
||||
FindName("NavView");
|
||||
}));
|
||||
}
|
||||
|
||||
private void App_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
|
||||
{
|
||||
if (m_model.IsAlwaysOnTop)
|
||||
{
|
||||
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
|
||||
localSettings.Values[ApplicationViewModel.WidthLocalSettings] = ActualWidth;
|
||||
localSettings.Values[ApplicationViewModel.HeightLocalSettings] = ActualHeight;
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureCalculator()
|
||||
{
|
||||
if (m_calculator == null)
|
||||
{
|
||||
// delay load calculator.
|
||||
m_calculator = new Calculator();
|
||||
m_calculator.Name = "Calculator";
|
||||
m_calculator.DataContext = m_model.CalculatorViewModel;
|
||||
Binding isStandardBinding = new Binding();
|
||||
isStandardBinding.Path = new PropertyPath("IsStandard");
|
||||
m_calculator.SetBinding(Calculator.IsStandardProperty, isStandardBinding);
|
||||
Binding isScientificBinding = new Binding();
|
||||
isScientificBinding.Path = new PropertyPath("IsScientific");
|
||||
m_calculator.SetBinding(Calculator.IsScientificProperty, isScientificBinding);
|
||||
Binding isProgramerBinding = new Binding();
|
||||
isProgramerBinding.Path = new PropertyPath("IsProgrammer");
|
||||
m_calculator.SetBinding(Calculator.IsProgrammerProperty, isProgramerBinding);
|
||||
Binding isAlwaysOnTopBinding = new Binding();
|
||||
isAlwaysOnTopBinding.Path = new PropertyPath("IsAlwaysOnTop");
|
||||
m_calculator.SetBinding(Calculator.IsAlwaysOnTopProperty, isAlwaysOnTopBinding);
|
||||
m_calculator.Style = CalculatorBaseStyle;
|
||||
|
||||
CalcHolder.Child = m_calculator;
|
||||
|
||||
// Calculator's "default" state is visible, but if we get delay loaded
|
||||
// when in converter, we should not be visible. This is not a problem for converter
|
||||
// since its default state is hidden.
|
||||
ShowHideControls(Model.Mode);
|
||||
}
|
||||
|
||||
if (m_dateCalculator != null)
|
||||
{
|
||||
m_dateCalculator.CloseCalendarFlyout();
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureDateCalculator()
|
||||
{
|
||||
if (m_dateCalculator == null)
|
||||
{
|
||||
// delay loading converter
|
||||
m_dateCalculator = new DateCalculator();
|
||||
m_dateCalculator.Name = "dateCalculator";
|
||||
m_dateCalculator.DataContext = m_model.DateCalcViewModel;
|
||||
|
||||
DateCalcHolder.Child = m_dateCalculator;
|
||||
}
|
||||
|
||||
if (m_calculator != null)
|
||||
{
|
||||
m_calculator.CloseHistoryFlyout();
|
||||
m_calculator.CloseMemoryFlyout();
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureGraphingCalculator()
|
||||
{
|
||||
if (m_graphingCalculator == null)
|
||||
{
|
||||
m_graphingCalculator = new GraphingCalculator();
|
||||
m_graphingCalculator.Name = "GraphingCalculator";
|
||||
m_graphingCalculator.DataContext = m_model.GraphingCalcViewModel;
|
||||
|
||||
GraphingCalcHolder.Child = m_graphingCalculator;
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureConverter()
|
||||
{
|
||||
if (m_converter == null)
|
||||
{
|
||||
// delay loading converter
|
||||
m_converter = new CalculatorApp.UnitConverter();
|
||||
m_converter.Name = "unitConverter";
|
||||
m_converter.DataContext = m_model.ConverterViewModel;
|
||||
m_converter.Style = UnitConverterBaseStyle;
|
||||
ConverterHolder.Child = m_converter;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowAboutPage()
|
||||
{
|
||||
if (AboutPage == null)
|
||||
{
|
||||
FindName("AboutPage");
|
||||
}
|
||||
|
||||
FlyoutBase.ShowAttachedFlyout(AboutButton);
|
||||
}
|
||||
|
||||
private void AnnounceCategoryName()
|
||||
{
|
||||
string categoryName = AutomationProperties.GetName(Header);
|
||||
NarratorAnnouncement announcement = CalculatorAnnouncement.GetCategoryNameChangedAnnouncement(categoryName);
|
||||
NarratorNotifier.Announce(announcement);
|
||||
}
|
||||
|
||||
private CalculatorApp.Calculator m_calculator;
|
||||
private GraphingCalculator m_graphingCalculator;
|
||||
private CalculatorApp.UnitConverter m_converter;
|
||||
private CalculatorApp.DateCalculator m_dateCalculator;
|
||||
private CalculatorApp.ViewModel.ApplicationViewModel m_model;
|
||||
private Windows.UI.ViewManagement.AccessibilitySettings m_accessibilitySettings;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue