Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Migration: Initially migrated C# codebase by Han #8

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
500 changes: 500 additions & 0 deletions src/Calculator/Controls/CalculationResult.cs

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions src/Calculator/Controls/CalculationResultAutomationPeer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Diagnostics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation.Peers;

namespace CalculatorApp
{
namespace Controls
{
public sealed class CalculationResultAutomationPeer : Windows.UI.Xaml.Automation.Peers.FrameworkElementAutomationPeer,
Windows.UI.Xaml.Automation.Provider.IInvokeProvider
{
public CalculationResultAutomationPeer(FrameworkElement owner) : base(owner)
{
}

protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Text;
}

protected override object GetPatternCore(PatternInterface pattern)
{
if (pattern == PatternInterface.Invoke)
{
return this;
}

return base.GetPatternCore(pattern);
}

public void Invoke()
{
var owner = (CalculationResult)this.Owner;
owner.ProgrammaticSelect();
}
}
}
}
134 changes: 134 additions & 0 deletions src/Calculator/Controls/CalculatorButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Diagnostics;
using CalculatorApp;
using CalculatorApp.Common;
using CalculatorApp.Controls;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Data;
using Windows.Foundation.Collections;
using Windows.Storage.Pickers;

namespace CalculatorApp
{
namespace Controls
{
public sealed class CalculatorButton : Windows.UI.Xaml.Controls.Button
{
public CalculatorButton()
{
// Set the default bindings for this button, these can be overwritten by Xaml if needed
// These are a replacement for binding in styles
Binding commandBinding = new Binding();
commandBinding.Path = new PropertyPath("ButtonPressed");
this.SetBinding(CommandProperty, commandBinding);
}

public NumbersAndOperatorsEnum ButtonId
{
get { return (NumbersAndOperatorsEnum)GetValue(ButtonIdProperty); }
set { SetValue(ButtonIdProperty, value); }
}

// Using a DependencyProperty as the backing store for ButtonId. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ButtonIdProperty =
DependencyProperty.Register("ButtonId", typeof(NumbersAndOperatorsEnum), typeof(CalculatorButton), new PropertyMetadata(default(NumbersAndOperatorsEnum), new PropertyChangedCallback((sender, args) =>
hanzhang54 marked this conversation as resolved.
Show resolved Hide resolved
{
var self = (CalculatorButton)sender;
self.OnButtonIdPropertyChanged((NumbersAndOperatorsEnum)args.OldValue, (NumbersAndOperatorsEnum)args.NewValue);
})));

public string AuditoryFeedback
{
get { return (string)GetValue(AuditoryFeedbackProperty); }
set { SetValue(AuditoryFeedbackProperty, value); }
}

// Using a DependencyProperty as the backing store for AuditoryFeedback. This enables animation, styling, binding, etc...
public static readonly DependencyProperty AuditoryFeedbackProperty =
DependencyProperty.Register("AuditoryFeedback", typeof(string), typeof(CalculatorButton), new PropertyMetadata(string.Empty, new PropertyChangedCallback((sender, args) =>
hanzhang54 marked this conversation as resolved.
Show resolved Hide resolved
{
var self = (CalculatorButton)sender;
self.OnAuditoryFeedbackPropertyChanged((string)args.OldValue, (string)args.NewValue);
})));

public Windows.UI.Xaml.Media.Brush HoverBackground
{
get { return (Windows.UI.Xaml.Media.Brush)GetValue(HoverBackgroundProperty); }
set { SetValue(HoverBackgroundProperty, value); }
}

// Using a DependencyProperty as the backing store for HoverBackground. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HoverBackgroundProperty =
DependencyProperty.Register(nameof(HoverBackground), typeof(Windows.UI.Xaml.Media.Brush), typeof(CalculatorButton), new PropertyMetadata(default(Windows.UI.Xaml.Media.Brush)));

public Windows.UI.Xaml.Media.Brush HoverForeground
{
get { return (Windows.UI.Xaml.Media.Brush)GetValue(HoverForegroundProperty); }
set { SetValue(HoverForegroundProperty, value); }
}

// Using a DependencyProperty as the backing store for HoverForeground. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HoverForegroundProperty =
DependencyProperty.Register(nameof(HoverForeground), typeof(Windows.UI.Xaml.Media.Brush), typeof(CalculatorButton), new PropertyMetadata(default(Windows.UI.Xaml.Media.Brush)));

public Windows.UI.Xaml.Media.Brush PressBackground
{
get { return (Windows.UI.Xaml.Media.Brush)GetValue(PressBackgroundProperty); }
set { SetValue(PressBackgroundProperty, value); }
}

// Using a DependencyProperty as the backing store for PressBackground. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PressBackgroundProperty =
DependencyProperty.Register(nameof(PressBackground), typeof(Windows.UI.Xaml.Media.Brush), typeof(CalculatorButton), new PropertyMetadata(default(Windows.UI.Xaml.Media.Brush)));

public Windows.UI.Xaml.Media.Brush PressForeground
{
get { return (Windows.UI.Xaml.Media.Brush)GetValue(PressForegroundProperty); }
set { SetValue(PressForegroundProperty, value); }
}

// Using a DependencyProperty as the backing store for PressForeground. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PressForegroundProperty =
DependencyProperty.Register(nameof(PressForeground), typeof(Windows.UI.Xaml.Media.Brush), typeof(CalculatorButton), new PropertyMetadata(default(Windows.UI.Xaml.Media.Brush)));

protected override void OnKeyDown(KeyRoutedEventArgs e)
{
// Ignore the Enter key
if (e.Key == VirtualKey.Enter)
{
return;
}

base.OnKeyDown(e);
}

protected override void OnKeyUp(KeyRoutedEventArgs e)
{
// Ignore the Enter key
if (e.Key == VirtualKey.Enter)
{
return;
}

base.OnKeyUp(e);
}

private void OnButtonIdPropertyChanged(NumbersAndOperatorsEnum oldValue, NumbersAndOperatorsEnum newValue)
{
this.CommandParameter = new CalculatorButtonPressedEventArgs(AuditoryFeedback, newValue);
}

private void OnAuditoryFeedbackPropertyChanged(string oldValue, string newValue)
{
this.CommandParameter = new CalculatorButtonPressedEventArgs(newValue, ButtonId);
}
}
}
}
102 changes: 102 additions & 0 deletions src/Calculator/Controls/OperatorPanelButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Diagnostics;

using Windows.Foundation;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using CalculatorApp;
using CalculatorApp.Common;
using CalculatorApp.Controls;

namespace CalculatorApp
{
namespace Controls
{
public sealed class OperatorPanelButton : Windows.UI.Xaml.Controls.Primitives.ToggleButton
{
public OperatorPanelButton()
{
}

public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}

// Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register(nameof(Text), typeof(string), typeof(OperatorPanelButton), new PropertyMetadata(string.Empty));

public string Glyph
{
get { return (string)GetValue(GlyphProperty); }
set { SetValue(GlyphProperty, value); }
}

// Using a DependencyProperty as the backing store for Glyph. This enables animation, styling, binding, etc...
public static readonly DependencyProperty GlyphProperty =
DependencyProperty.Register(nameof(Glyph), typeof(string), typeof(OperatorPanelButton), new PropertyMetadata(string.Empty));

public double GlyphFontSize
{
get { return (double)GetValue(GlyphFontSizeProperty); }
set { SetValue(GlyphFontSizeProperty, value); }
}

// Using a DependencyProperty as the backing store for GlyphFontSize. This enables animation, styling, binding, etc...
public static readonly DependencyProperty GlyphFontSizeProperty =
DependencyProperty.Register(nameof(GlyphFontSize), typeof(double), typeof(OperatorPanelButton), new PropertyMetadata(default(double)));

public double ChevronFontSize
{
get { return (double)GetValue(ChevronFontSizeProperty); }
set { SetValue(ChevronFontSizeProperty, value); }
}

// Using a DependencyProperty as the backing store for ChevronFontSize. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ChevronFontSizeProperty =
DependencyProperty.Register(nameof(ChevronFontSize), typeof(double), typeof(OperatorPanelButton), new PropertyMetadata(default(double)));

public Flyout FlyoutMenu
{
get { return (Flyout)GetValue(FlyoutMenuProperty); }
set { SetValue(FlyoutMenuProperty, value); }
}

// Using a DependencyProperty as the backing store for FlyoutMenu. This enables animation, styling, binding, etc...
public static readonly DependencyProperty FlyoutMenuProperty =
DependencyProperty.Register(nameof(FlyoutMenu), typeof(Flyout), typeof(OperatorPanelButton), new PropertyMetadata(default(Flyout)));

protected override void OnApplyTemplate()
{
if (FlyoutMenu != null)
{
FlyoutMenu.Closed += FlyoutClosed;
}
}

protected override void OnToggle()
{
base.OnToggle();

if (IsChecked == true)
{
FlyoutMenu.ShowAt(this);
}
}

private void FlyoutClosed(object sender, object args)
{
IsChecked = false;
}
}
}
}
Loading