diff --git a/src/Calculator.Shared/ViewModels/StandardCalculatorViewModel.cs b/src/Calculator.Shared/ViewModels/StandardCalculatorViewModel.cs
index 786850a0..18d93169 100644
--- a/src/Calculator.Shared/ViewModels/StandardCalculatorViewModel.cs
+++ b/src/Calculator.Shared/ViewModels/StandardCalculatorViewModel.cs
@@ -1518,7 +1518,7 @@ namespace CalculatorApp.ViewModel
}
}
- void OnMemoryItemPressed(object memoryItemPosition)
+ public void OnMemoryItemPressed(object memoryItemPosition)
{
if (MemorizedNumbers != null && MemorizedNumbers.Count > 0)
{
diff --git a/src/Calculator.Shared/Views/Memory.xaml b/src/Calculator.Shared/Views/Memory.xaml
index e37b0b54..674499dc 100644
--- a/src/Calculator.Shared/Views/Memory.xaml
+++ b/src/Calculator.Shared/Views/Memory.xaml
@@ -4,177 +4,132 @@
xmlns:common="using:CalculatorApp.Common"
xmlns:controls="using:CalculatorApp.Controls"
xmlns:converters="using:CalculatorApp.Converters"
- xmlns:local="using:CalculatorApp.Views"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:local="using:CalculatorApp"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:model="using:CalculatorApp.ViewModel"
x:Name="MemoryList"
FlowDirection="LeftToRight"
- mc:Ignorable="">
+ mc:Ignorable="d">
-
-
-
+
-
diff --git a/src/Calculator.Shared/Views/Memory.xaml.cs b/src/Calculator.Shared/Views/Memory.xaml.cs
index 5bc5a789..17ab5069 100644
--- a/src/Calculator.Shared/Views/Memory.xaml.cs
+++ b/src/Calculator.Shared/Views/Memory.xaml.cs
@@ -1,29 +1,125 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+// xaml.h
+// Declaration of the Memory class
+//
+
+using CalculatorApp.Common;
+using CalculatorApp.ViewModel;
using Windows.Foundation;
-using Windows.Foundation.Collections;
using Windows.UI.Xaml;
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.Media;
-using Windows.UI.Xaml.Navigation;
-
-// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace CalculatorApp
{
- public sealed partial class Memory : UserControl
+ public partial class Memory
{
- public Memory()
+ private Windows.UI.Xaml.Controls.MenuFlyout m_memoryItemFlyout;
+ private bool m_isErrorVisualState;
+
+ public CalculatorApp.ViewModel.StandardCalculatorViewModel Model => (CalculatorApp.ViewModel.StandardCalculatorViewModel)(this.DataContext);
+
+ public GridLength RowHeight
{
- this.InitializeComponent();
+ get { return (GridLength)GetValue(RowHeightProperty); }
+ set { SetValue(RowHeightProperty, value); }
}
- public bool IsErrorVisualState { get; set; }
- }
+ public static readonly DependencyProperty RowHeightProperty =
+ DependencyProperty.Register("RowHeight", typeof(GridLength), typeof(Memory), new PropertyMetadata(GridLength.Auto));
+
+ public Memory()
+ {
+ m_isErrorVisualState = false;
+ InitializeComponent();
+ m_memoryItemFlyout = (MenuFlyout)(Resources["MemoryContextMenu"]);
+
+ MemoryPaneEmpty.FlowDirection = LocalizationService.GetInstance().GetFlowDirection();
+ }
+
+ void MemoryListItemClick(object sender, ItemClickEventArgs e)
+ {
+ MemoryItemViewModel memorySlot = (MemoryItemViewModel)(e.ClickedItem);
+
+ // In case the memory list is clicked and enter is pressed,
+ // On Item clicked event gets fired and e.ClickedItem is Null.
+ if (memorySlot != null)
+ {
+ Model.OnMemoryItemPressed(memorySlot.Position);
+ }
+ }
+
+ void OnContextRequested(Windows.UI.Xaml.UIElement sender, Windows.UI.Xaml.Input.ContextRequestedEventArgs e)
+ {
+ // Walk up the tree to find the ListViewItem.
+ // There may not be one if the click wasn't on an item.
+ var requestedElement = (FrameworkElement)(e.OriginalSource);
+ while ((requestedElement != sender) && !(requestedElement is ListViewItem))
+ {
+ requestedElement = (FrameworkElement)(VisualTreeHelper.GetParent(requestedElement));
+ }
+
+ if (requestedElement != sender)
+ {
+ // The context menu request was for a ListViewItem.
+ var memorySlot = (MemoryItemViewModel)(MemoryListView.ItemFromContainer(requestedElement));
+ Point point;
+ if (e.TryGetPosition(requestedElement, out point))
+ {
+ m_memoryItemFlyout.ShowAt(requestedElement, point);
+ }
+ else
+ {
+ // Not invoked via pointer, so let XAML choose a default location.
+ m_memoryItemFlyout.ShowAt(requestedElement);
+ }
+
+ e.Handled = true;
+ }
+ }
+
+ void OnContextCanceled(Windows.UI.Xaml.UIElement sender, Windows.UI.Xaml.RoutedEventArgs e)
+ {
+ m_memoryItemFlyout.Hide();
+ }
+
+ void OnClearMenuItemClicked(object sender, RoutedEventArgs e)
+ {
+ GetMemoryItemForCurrentFlyout().Clear();
+ }
+
+ void OnMemoryAddMenuItemClicked(object sender, RoutedEventArgs e)
+ {
+ GetMemoryItemForCurrentFlyout().MemoryAdd();
+ }
+
+ void OnMemorySubtractMenuItemClicked(object sender, RoutedEventArgs e)
+ {
+ GetMemoryItemForCurrentFlyout().MemorySubtract();
+ }
+
+ public bool IsErrorVisualState
+ {
+ get => m_isErrorVisualState;
+ set
+ {
+ if (m_isErrorVisualState != value)
+ {
+ m_isErrorVisualState = value;
+ string newState = m_isErrorVisualState ? "ErrorLayout" : "NoErrorLayout";
+ VisualStateManager.GoToState(this, newState, false);
+ }
+ }
+ }
+
+ MemoryItemViewModel GetMemoryItemForCurrentFlyout()
+ {
+ var listViewItem = m_memoryItemFlyout.Target;
+
+ return (MemoryItemViewModel)(MemoryListView.ItemFromContainer(listViewItem));
+ }
+ }
}
diff --git a/src/Calculator.Shared/Views/MemoryListItem.xaml b/src/Calculator.Shared/Views/MemoryListItem.xaml
index c54fe069..519b68dd 100644
--- a/src/Calculator.Shared/Views/MemoryListItem.xaml
+++ b/src/Calculator.Shared/Views/MemoryListItem.xaml
@@ -1,116 +1,108 @@
-
+ mc:Ignorable="d">
+
+ Background="{ThemeResource SystemControlBackgroundAccentBrush}"
+ IconSource="{StaticResource MemMinusGlyph}"
+ Invoked="OnMemorySubtractSwipeInvoked"/>
+
+
+
-
+
+
-
+
-
+
-
-
-
+
+
-
-
+ HorizontalAlignment="Right"
+ Style="{ThemeResource TitleTextBlockStyle}"
+ FontWeight="SemiBold"
+ FlowDirection="LeftToRight"
+ IsTextSelectionEnabled="True"
+ Text="{x:Bind Model.Value, Mode=OneWay}"
+ TextAlignment="Right"
+ TextReadingOrder="DetectFromContent"
+ TextWrapping="Wrap"/>
+ Grid.Row="1"
+ Margin="0,0,10,2"
+ HorizontalAlignment="Right"
+ Opacity="0">
-
-
-
+
+
+
-
-
+ Style="{StaticResource MemoryHoverButtonStyle}"
+ Background="{ThemeResource SystemControlBackgroundAltMediumHighBrush}"
+ AutomationProperties.AutomationId="MClearButton"
+ Click="OnClearButtonClicked"
+ Content="MC"/>
-
+ Grid.Column="1"
+ Margin="0"
+ Style="{StaticResource MemoryHoverButtonStyle}"
+ Background="{ThemeResource SystemControlBackgroundAltMediumHighBrush}"
+ AutomationProperties.AutomationId="MAddButton"
+ Click="OnMemoryAddButtonClicked"
+ Content="M+"/>
+ Grid.Column="2"
+ Style="{StaticResource MemoryHoverButtonStyle}"
+ Background="{ThemeResource SystemControlBackgroundAltMediumHighBrush}"
+ AutomationProperties.AutomationId="MSubButton"
+ Click="OnMemorySubtractButtonClicked"
+ Content="M-"/>
- -->
-
\ No newline at end of file
+
+
diff --git a/src/Calculator.Shared/Views/MemoryListItem.xaml.cs b/src/Calculator.Shared/Views/MemoryListItem.xaml.cs
index d887c0c2..9a755863 100644
--- a/src/Calculator.Shared/Views/MemoryListItem.xaml.cs
+++ b/src/Calculator.Shared/Views/MemoryListItem.xaml.cs
@@ -1,27 +1,81 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
-using Windows.Foundation;
-using Windows.Foundation.Collections;
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using CalculatorApp.ViewModel;
using Windows.UI.Xaml;
-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.Media;
-using Windows.UI.Xaml.Navigation;
-// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
-
-namespace WindowsCalculator.Shared.Views
+namespace CalculatorApp
{
- public sealed partial class MemoryListItem : UserControl
+ ///
+ /// Represents a single item in the Memory list.
+ ///
+ public partial class MemoryListItem
{
+
+ public MemoryItemViewModel Model
+ {
+ get { return (MemoryItemViewModel)GetValue(ModelProperty); }
+ set { SetValue(ModelProperty, value); }
+ }
+
+ // Using a DependencyProperty as the backing store for Model. This enables animation, styling, binding, etc...
+ public static readonly DependencyProperty ModelProperty =
+ DependencyProperty.Register("Model", typeof(MemoryItemViewModel), typeof(MemoryListItem), new PropertyMetadata(null));
+
public MemoryListItem()
{
- this.InitializeComponent();
+ InitializeComponent();
}
- }
+
+ protected override void OnPointerEntered(Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
+ {
+ base.OnPointerEntered(e);
+
+ // Only show hover buttons when the user is using mouse or pen.
+ if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse
+ || e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Pen)
+ {
+ VisualStateManager.GoToState(this, "MemoryButtonsVisible", true);
+ }
+ }
+
+ protected override void OnPointerExited(Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
+ {
+ base.OnPointerExited(e);
+
+ VisualStateManager.GoToState(this, "MemoryButtonsHidden", true);
+ }
+
+ void OnClearButtonClicked(object sender, RoutedEventArgs e)
+ {
+ Model.Clear();
+ }
+
+ void OnMemoryAddButtonClicked(object sender, RoutedEventArgs e)
+ {
+ Model.MemoryAdd();
+ }
+
+ void OnMemorySubtractButtonClicked(object sender, RoutedEventArgs e)
+ {
+ Model.MemorySubtract();
+ }
+
+#if false
+ void OnClearSwipeInvoked(object sender, SwipeItemInvokedEventArgs e)
+ {
+ Model.Clear();
+ }
+
+ void OnMemoryAddSwipeInvoked(object sender, SwipeItemInvokedEventArgs e)
+ {
+ Model.MemoryAdd();
+ }
+
+ void OnMemorySubtractSwipeInvoked(object sender, SwipeItemInvokedEventArgs e)
+ {
+ Model.MemorySubtract();
+ }
+#endif
+ };
}