mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 22:23:29 -07:00
Merge pull request #34 from nventive/dev/jela/missing-propertychange
Add missing property changed handers
This commit is contained in:
commit
30acea5fba
6 changed files with 829 additions and 753 deletions
File diff suppressed because it is too large
Load diff
|
@ -31,17 +31,17 @@ namespace CalculatorApp.Controls
|
|||
|
||||
public static readonly DependencyProperty ButtonIdProperty =
|
||||
DependencyProperty.Register(
|
||||
"ButtonId",
|
||||
typeof(NumbersAndOperatorsEnum),
|
||||
typeof(CalculatorButton),
|
||||
new PropertyMetadata(
|
||||
null,
|
||||
(s, e) => (s as CalculatorButton)?.OnButtonIdPropertyChanged(
|
||||
(NumbersAndOperatorsEnum)(e.OldValue ?? NumbersAndOperatorsEnum.None),
|
||||
(NumbersAndOperatorsEnum)(e.NewValue ?? NumbersAndOperatorsEnum.None)
|
||||
)
|
||||
)
|
||||
);
|
||||
"ButtonId",
|
||||
typeof(NumbersAndOperatorsEnum),
|
||||
typeof(CalculatorButton),
|
||||
new PropertyMetadata(
|
||||
null,
|
||||
(s, e) => (s as CalculatorButton)?.OnButtonIdPropertyChanged(
|
||||
(NumbersAndOperatorsEnum)(e.OldValue ?? NumbersAndOperatorsEnum.None),
|
||||
(NumbersAndOperatorsEnum)(e.NewValue ?? NumbersAndOperatorsEnum.None)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// AuditoryFeedback
|
||||
public string AuditoryFeedback
|
||||
|
@ -51,7 +51,15 @@ namespace CalculatorApp.Controls
|
|||
}
|
||||
|
||||
public static readonly DependencyProperty AuditoryFeedbackProperty =
|
||||
DependencyProperty.Register("AuditoryFeedback", typeof(string), typeof(CalculatorButton), new PropertyMetadata(null));
|
||||
DependencyProperty.Register(
|
||||
name: "AuditoryFeedback",
|
||||
propertyType: typeof(string),
|
||||
ownerType: typeof(CalculatorButton),
|
||||
typeMetadata: new PropertyMetadata(
|
||||
defaultValue: null,
|
||||
propertyChangedCallback: (s, e) => (s as CalculatorButton)?.OnAuditoryFeedbackPropertyChanged(
|
||||
oldValue: e.OldValue as string,
|
||||
newValue: e.NewValue as string)));
|
||||
|
||||
// HoverBackground
|
||||
public Brush HoverBackground
|
||||
|
@ -106,7 +114,7 @@ namespace CalculatorApp.Controls
|
|||
base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
protected override void OnKeyUp(KeyRoutedEventArgs e)
|
||||
protected override void OnKeyUp(KeyRoutedEventArgs e)
|
||||
{
|
||||
// Ignore the Enter key
|
||||
if (e.Key == VirtualKey.Enter)
|
||||
|
@ -114,7 +122,7 @@ namespace CalculatorApp.Controls
|
|||
return;
|
||||
}
|
||||
|
||||
base.OnKeyUp(e);
|
||||
base.OnKeyUp(e);
|
||||
}
|
||||
|
||||
// PRIVATE
|
||||
|
|
|
@ -13,7 +13,6 @@ namespace CalculatorApp.Controls
|
|||
{
|
||||
public partial class FlipButtons : ToggleButton
|
||||
{
|
||||
|
||||
// NumbersAndOperatorsEnum
|
||||
public NumbersAndOperatorsEnum ButtonId
|
||||
{
|
||||
|
@ -22,7 +21,15 @@ namespace CalculatorApp.Controls
|
|||
}
|
||||
|
||||
public static readonly DependencyProperty ButtonIdProperty =
|
||||
DependencyProperty.Register("ButtonId", typeof(NumbersAndOperatorsEnum), typeof(FlipButtons), new PropertyMetadata(null));
|
||||
DependencyProperty.Register(
|
||||
name: "ButtonId",
|
||||
propertyType: typeof(NumbersAndOperatorsEnum),
|
||||
ownerType: typeof(FlipButtons),
|
||||
typeMetadata: new PropertyMetadata(
|
||||
defaultValue: NumbersAndOperatorsEnum.None,
|
||||
propertyChangedCallback: (s, e) => (s as FlipButtons)?.OnButtonIdPropertyChanged(
|
||||
(NumbersAndOperatorsEnum)(e.OldValue ?? NumbersAndOperatorsEnum.None),
|
||||
(NumbersAndOperatorsEnum)(e.NewValue ?? NumbersAndOperatorsEnum.None))));
|
||||
|
||||
// HoverBackground
|
||||
public Brush HoverBackground
|
||||
|
|
|
@ -17,252 +17,261 @@ using Windows.UI.Xaml.Media;
|
|||
|
||||
namespace CalculatorApp.Controls
|
||||
{
|
||||
public partial class OverflowTextBlock : Control
|
||||
{
|
||||
const double scrollRatio = 0.7;
|
||||
public partial class OverflowTextBlock : Control
|
||||
{
|
||||
const double scrollRatio = 0.7;
|
||||
|
||||
bool m_scrollingLeft;
|
||||
bool m_scrollingRight;
|
||||
bool m_scrollingLeft;
|
||||
bool m_scrollingRight;
|
||||
|
||||
ListView m_listView;
|
||||
ScrollViewer m_expressionContainer;
|
||||
Button m_scrollLeft;
|
||||
Button m_scrollRight;
|
||||
ListView m_listView;
|
||||
ScrollViewer m_expressionContainer;
|
||||
Button m_scrollLeft;
|
||||
Button m_scrollRight;
|
||||
|
||||
EventRegistrationToken m_scrollLeftClickEventToken;
|
||||
EventRegistrationToken m_scrollRightClickEventToken;
|
||||
EventRegistrationToken m_pointerEnteredEventToken;
|
||||
EventRegistrationToken m_pointerExitedEventToken;
|
||||
private ItemsControl m_itemsControl;
|
||||
private bool m_isAccessibilityViewControl;
|
||||
EventRegistrationToken m_scrollLeftClickEventToken;
|
||||
EventRegistrationToken m_scrollRightClickEventToken;
|
||||
EventRegistrationToken m_pointerEnteredEventToken;
|
||||
EventRegistrationToken m_pointerExitedEventToken;
|
||||
private ItemsControl m_itemsControl;
|
||||
private bool m_isAccessibilityViewControl;
|
||||
|
||||
|
||||
|
||||
public bool TokensUpdated
|
||||
{
|
||||
get { return (bool)GetValue(TokensUpdatedProperty); }
|
||||
set { SetValue(TokensUpdatedProperty, value); }
|
||||
}
|
||||
public bool TokensUpdated
|
||||
{
|
||||
get { return (bool)GetValue(TokensUpdatedProperty); }
|
||||
set { SetValue(TokensUpdatedProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TokensUpdatedProperty =
|
||||
DependencyProperty.Register("TokensUpdated", typeof(bool), typeof(OverflowTextBlock), new PropertyMetadata(false));
|
||||
public static readonly DependencyProperty TokensUpdatedProperty =
|
||||
DependencyProperty.Register(
|
||||
name: "TokensUpdated",
|
||||
propertyType: typeof(bool),
|
||||
ownerType: typeof(OverflowTextBlock),
|
||||
typeMetadata: new PropertyMetadata(
|
||||
false,
|
||||
(s, e) => (s as OverflowTextBlock)?.OnTokensUpdatedPropertyChanged(
|
||||
oldValue: (bool)e.OldValue,
|
||||
newValue: (bool)e.NewValue
|
||||
)));
|
||||
|
||||
|
||||
|
||||
public bool IsActive
|
||||
{
|
||||
get { return (bool)GetValue(IsActiveProperty); }
|
||||
set { SetValue(IsActiveProperty, value); }
|
||||
}
|
||||
public bool IsActive
|
||||
{
|
||||
get { return (bool)GetValue(IsActiveProperty); }
|
||||
set { SetValue(IsActiveProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsActiveProperty =
|
||||
DependencyProperty.Register("IsActive", typeof(bool), typeof(OverflowTextBlock), new PropertyMetadata(false));
|
||||
public static readonly DependencyProperty IsActiveProperty =
|
||||
DependencyProperty.Register("IsActive", typeof(bool), typeof(OverflowTextBlock), new PropertyMetadata(false));
|
||||
|
||||
|
||||
|
||||
public Style TextStyle
|
||||
{
|
||||
get { return (Style)GetValue(TextStyleProperty); }
|
||||
set { SetValue(TextStyleProperty, value); }
|
||||
}
|
||||
public Style TextStyle
|
||||
{
|
||||
get { return (Style)GetValue(TextStyleProperty); }
|
||||
set { SetValue(TextStyleProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TextStyleProperty =
|
||||
DependencyProperty.Register("TextStyle", typeof(Style), typeof(OverflowTextBlock), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty TextStyleProperty =
|
||||
DependencyProperty.Register("TextStyle", typeof(Style), typeof(OverflowTextBlock), new PropertyMetadata(null));
|
||||
|
||||
|
||||
protected override void OnApplyTemplate()
|
||||
{
|
||||
UnregisterEventHandlers();
|
||||
protected override void OnApplyTemplate()
|
||||
{
|
||||
UnregisterEventHandlers();
|
||||
|
||||
var uiElement = GetTemplateChild("ExpressionContainer");
|
||||
if (uiElement != null)
|
||||
{
|
||||
m_expressionContainer = uiElement as ScrollViewer;
|
||||
m_expressionContainer.ChangeView(m_expressionContainer.ExtentWidth - m_expressionContainer.ViewportWidth, null, null);
|
||||
m_expressionContainer.ViewChanged += OnViewChanged;
|
||||
}
|
||||
var uiElement = GetTemplateChild("ExpressionContainer");
|
||||
if (uiElement != null)
|
||||
{
|
||||
m_expressionContainer = uiElement as ScrollViewer;
|
||||
m_expressionContainer.ChangeView(m_expressionContainer.ExtentWidth - m_expressionContainer.ViewportWidth, null, null);
|
||||
m_expressionContainer.ViewChanged += OnViewChanged;
|
||||
}
|
||||
|
||||
uiElement = GetTemplateChild("ScrollLeft");
|
||||
if (uiElement != null)
|
||||
{
|
||||
m_scrollLeft = (uiElement as Button);
|
||||
m_scrollLeft.Click += OnScrollClick;
|
||||
}
|
||||
uiElement = GetTemplateChild("ScrollLeft");
|
||||
if (uiElement != null)
|
||||
{
|
||||
m_scrollLeft = (uiElement as Button);
|
||||
m_scrollLeft.Click += OnScrollClick;
|
||||
}
|
||||
|
||||
uiElement = GetTemplateChild("ScrollRight");
|
||||
if (uiElement != null)
|
||||
{
|
||||
m_scrollRight = (uiElement as Button);
|
||||
m_scrollRight.Click += OnScrollClick;
|
||||
}
|
||||
uiElement = GetTemplateChild("ScrollRight");
|
||||
if (uiElement != null)
|
||||
{
|
||||
m_scrollRight = (uiElement as Button);
|
||||
m_scrollRight.Click += OnScrollClick;
|
||||
}
|
||||
|
||||
m_scrollingLeft = false;
|
||||
m_scrollingRight = false;
|
||||
m_scrollingLeft = false;
|
||||
m_scrollingRight = false;
|
||||
|
||||
uiElement = GetTemplateChild("TokenList");
|
||||
if (uiElement != null)
|
||||
{
|
||||
m_itemsControl = (uiElement as ItemsControl);
|
||||
}
|
||||
uiElement = GetTemplateChild("TokenList");
|
||||
if (uiElement != null)
|
||||
{
|
||||
m_itemsControl = (uiElement as ItemsControl);
|
||||
}
|
||||
|
||||
UpdateAllState();
|
||||
}
|
||||
UpdateAllState();
|
||||
}
|
||||
|
||||
AutomationPeer OnCreateAutomationPeer()
|
||||
{
|
||||
return new OverflowTextBlockAutomationPeer(this);
|
||||
}
|
||||
AutomationPeer OnCreateAutomationPeer()
|
||||
{
|
||||
return new OverflowTextBlockAutomationPeer(this);
|
||||
}
|
||||
|
||||
void OnTokensUpdatedPropertyChanged(bool oldValue, bool newValue)
|
||||
{
|
||||
if (m_expressionContainer != null && newValue)
|
||||
{
|
||||
m_expressionContainer.UpdateLayout();
|
||||
m_expressionContainer.ChangeView(m_expressionContainer.ScrollableWidth, null, null, true);
|
||||
}
|
||||
var newIsAccessibilityViewControl = m_itemsControl != null && m_itemsControl.Items.Count > 0;
|
||||
if (m_isAccessibilityViewControl != newIsAccessibilityViewControl)
|
||||
{
|
||||
m_isAccessibilityViewControl = newIsAccessibilityViewControl;
|
||||
AutomationProperties.SetAccessibilityView(this, newIsAccessibilityViewControl ? AccessibilityView.Control : AccessibilityView.Raw);
|
||||
}
|
||||
UpdateScrollButtons();
|
||||
}
|
||||
void OnTokensUpdatedPropertyChanged(bool oldValue, bool newValue)
|
||||
{
|
||||
if (m_expressionContainer != null && newValue)
|
||||
{
|
||||
m_expressionContainer.UpdateLayout();
|
||||
m_expressionContainer.ChangeView(m_expressionContainer.ScrollableWidth, null, null, true);
|
||||
}
|
||||
var newIsAccessibilityViewControl = m_itemsControl != null && m_itemsControl.Items.Count > 0;
|
||||
if (m_isAccessibilityViewControl != newIsAccessibilityViewControl)
|
||||
{
|
||||
m_isAccessibilityViewControl = newIsAccessibilityViewControl;
|
||||
AutomationProperties.SetAccessibilityView(this, newIsAccessibilityViewControl ? AccessibilityView.Control : AccessibilityView.Raw);
|
||||
}
|
||||
UpdateScrollButtons();
|
||||
}
|
||||
|
||||
void UpdateAllState()
|
||||
{
|
||||
UpdateVisualState();
|
||||
}
|
||||
void UpdateAllState()
|
||||
{
|
||||
UpdateVisualState();
|
||||
}
|
||||
|
||||
void UpdateVisualState()
|
||||
{
|
||||
if (IsActive)
|
||||
{
|
||||
VisualStateManager.GoToState(this, "Active", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
VisualStateManager.GoToState(this, "Normal", true);
|
||||
}
|
||||
}
|
||||
void UpdateVisualState()
|
||||
{
|
||||
if (IsActive)
|
||||
{
|
||||
VisualStateManager.GoToState(this, "Active", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
VisualStateManager.GoToState(this, "Normal", true);
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollLeft()
|
||||
{
|
||||
if (m_expressionContainer != null && m_expressionContainer.HorizontalOffset > 0)
|
||||
{
|
||||
m_scrollingLeft = true;
|
||||
double offset = m_expressionContainer.HorizontalOffset - (scrollRatio * m_expressionContainer.ViewportWidth);
|
||||
m_expressionContainer.ChangeView(offset, null, null);
|
||||
m_expressionContainer.UpdateLayout();
|
||||
UpdateScrollButtons();
|
||||
}
|
||||
}
|
||||
void ScrollLeft()
|
||||
{
|
||||
if (m_expressionContainer != null && m_expressionContainer.HorizontalOffset > 0)
|
||||
{
|
||||
m_scrollingLeft = true;
|
||||
double offset = m_expressionContainer.HorizontalOffset - (scrollRatio * m_expressionContainer.ViewportWidth);
|
||||
m_expressionContainer.ChangeView(offset, null, null);
|
||||
m_expressionContainer.UpdateLayout();
|
||||
UpdateScrollButtons();
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollRight()
|
||||
{
|
||||
if (m_expressionContainer != null && m_expressionContainer.HorizontalOffset < m_expressionContainer.ExtentWidth - m_expressionContainer.ViewportWidth)
|
||||
{
|
||||
m_scrollingRight = true;
|
||||
double offset = m_expressionContainer.HorizontalOffset + (scrollRatio * m_expressionContainer.ViewportWidth);
|
||||
m_expressionContainer.ChangeView(offset, null, null);
|
||||
m_expressionContainer.UpdateLayout();
|
||||
UpdateScrollButtons();
|
||||
}
|
||||
}
|
||||
void ScrollRight()
|
||||
{
|
||||
if (m_expressionContainer != null && m_expressionContainer.HorizontalOffset < m_expressionContainer.ExtentWidth - m_expressionContainer.ViewportWidth)
|
||||
{
|
||||
m_scrollingRight = true;
|
||||
double offset = m_expressionContainer.HorizontalOffset + (scrollRatio * m_expressionContainer.ViewportWidth);
|
||||
m_expressionContainer.ChangeView(offset, null, null);
|
||||
m_expressionContainer.UpdateLayout();
|
||||
UpdateScrollButtons();
|
||||
}
|
||||
}
|
||||
|
||||
void OnScrollClick(object sender, RoutedEventArgs args)
|
||||
{
|
||||
var clicked = (sender as Button);
|
||||
if (clicked == m_scrollLeft)
|
||||
{
|
||||
ScrollLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
ScrollRight();
|
||||
}
|
||||
}
|
||||
void OnScrollClick(object sender, RoutedEventArgs args)
|
||||
{
|
||||
var clicked = (sender as Button);
|
||||
if (clicked == m_scrollLeft)
|
||||
{
|
||||
ScrollLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
ScrollRight();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateScrollButtons()
|
||||
{
|
||||
if (m_itemsControl == null || m_expressionContainer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
void UpdateScrollButtons()
|
||||
{
|
||||
if (m_itemsControl == null || m_expressionContainer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// When the width is smaller than the container, don't show any
|
||||
if (m_itemsControl.ActualWidth <= m_expressionContainer.ActualWidth)
|
||||
{
|
||||
ShowHideScrollButtons(Visibility.Collapsed, Visibility.Collapsed);
|
||||
}
|
||||
// We have more number on both side. Show both arrows
|
||||
else if (
|
||||
(m_expressionContainer.HorizontalOffset > 0)
|
||||
&& (m_expressionContainer.HorizontalOffset < (m_expressionContainer.ExtentWidth - m_expressionContainer.ViewportWidth)))
|
||||
{
|
||||
ShowHideScrollButtons(Visibility.Visible, Visibility.Visible);
|
||||
}
|
||||
// Width is larger than the container and left most part of the number is shown. Should be able to scroll left.
|
||||
else if (m_expressionContainer.HorizontalOffset == 0)
|
||||
{
|
||||
ShowHideScrollButtons(Visibility.Collapsed, Visibility.Visible);
|
||||
if (m_scrollingLeft)
|
||||
{
|
||||
m_scrollingLeft = false;
|
||||
if (m_scrollRight != null)
|
||||
{
|
||||
m_scrollRight.Focus(FocusState.Programmatic);
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Width is larger than the container and right most part of the number is shown. Should be able to scroll left.
|
||||
{
|
||||
ShowHideScrollButtons(Visibility.Visible, Visibility.Collapsed);
|
||||
if (m_scrollingRight)
|
||||
{
|
||||
m_scrollingRight = false;
|
||||
if (m_scrollLeft != null)
|
||||
{
|
||||
m_scrollLeft.Focus(FocusState.Programmatic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// When the width is smaller than the container, don't show any
|
||||
if (m_itemsControl.ActualWidth <= m_expressionContainer.ActualWidth)
|
||||
{
|
||||
ShowHideScrollButtons(Visibility.Collapsed, Visibility.Collapsed);
|
||||
}
|
||||
// We have more number on both side. Show both arrows
|
||||
else if (
|
||||
(m_expressionContainer.HorizontalOffset > 0)
|
||||
&& (m_expressionContainer.HorizontalOffset < (m_expressionContainer.ExtentWidth - m_expressionContainer.ViewportWidth)))
|
||||
{
|
||||
ShowHideScrollButtons(Visibility.Visible, Visibility.Visible);
|
||||
}
|
||||
// Width is larger than the container and left most part of the number is shown. Should be able to scroll left.
|
||||
else if (m_expressionContainer.HorizontalOffset == 0)
|
||||
{
|
||||
ShowHideScrollButtons(Visibility.Collapsed, Visibility.Visible);
|
||||
if (m_scrollingLeft)
|
||||
{
|
||||
m_scrollingLeft = false;
|
||||
if (m_scrollRight != null)
|
||||
{
|
||||
m_scrollRight.Focus(FocusState.Programmatic);
|
||||
}
|
||||
}
|
||||
}
|
||||
else // Width is larger than the container and right most part of the number is shown. Should be able to scroll left.
|
||||
{
|
||||
ShowHideScrollButtons(Visibility.Visible, Visibility.Collapsed);
|
||||
if (m_scrollingRight)
|
||||
{
|
||||
m_scrollingRight = false;
|
||||
if (m_scrollLeft != null)
|
||||
{
|
||||
m_scrollLeft.Focus(FocusState.Programmatic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShowHideScrollButtons(Visibility vLeft, Visibility vRight)
|
||||
{
|
||||
if (m_scrollLeft != null && m_scrollRight != null)
|
||||
{
|
||||
m_scrollLeft.Visibility = vLeft;
|
||||
m_scrollRight.Visibility = vRight;
|
||||
}
|
||||
}
|
||||
void ShowHideScrollButtons(Visibility vLeft, Visibility vRight)
|
||||
{
|
||||
if (m_scrollLeft != null && m_scrollRight != null)
|
||||
{
|
||||
m_scrollLeft.Visibility = vLeft;
|
||||
m_scrollRight.Visibility = vRight;
|
||||
}
|
||||
}
|
||||
|
||||
public void UnregisterEventHandlers()
|
||||
{
|
||||
// UNO TODO Unregister
|
||||
public void UnregisterEventHandlers()
|
||||
{
|
||||
// UNO TODO Unregister
|
||||
|
||||
// Unregister the event handlers
|
||||
//if (m_scrollLeft != null)
|
||||
//{
|
||||
// m_scrollLeft.Click -= m_scrollLeftClickEventToken;
|
||||
//}
|
||||
// Unregister the event handlers
|
||||
//if (m_scrollLeft != null)
|
||||
//{
|
||||
// m_scrollLeft.Click -= m_scrollLeftClickEventToken;
|
||||
//}
|
||||
|
||||
//if (m_scrollRight != null)
|
||||
//{
|
||||
// m_scrollRight.Click -= m_scrollRightClickEventToken;
|
||||
//}
|
||||
//if (m_scrollRight != null)
|
||||
//{
|
||||
// m_scrollRight.Click -= m_scrollRightClickEventToken;
|
||||
//}
|
||||
|
||||
//if (m_expressionContainer != null)
|
||||
//{
|
||||
// m_expressionContainer.ViewChanged -= m_containerViewChangedToken;
|
||||
//}
|
||||
}
|
||||
//if (m_expressionContainer != null)
|
||||
//{
|
||||
// m_expressionContainer.ViewChanged -= m_containerViewChangedToken;
|
||||
//}
|
||||
}
|
||||
|
||||
void OnViewChanged(object sender, ScrollViewerViewChangedEventArgs args)
|
||||
{
|
||||
UpdateScrollButtons();
|
||||
}
|
||||
void OnViewChanged(object sender, ScrollViewerViewChangedEventArgs args)
|
||||
{
|
||||
UpdateScrollButtons();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,16 @@ namespace CalculatorApp
|
|||
}
|
||||
|
||||
public static readonly DependencyProperty IsErrorVisualStateProperty =
|
||||
DependencyProperty.Register("IsErrorVisualState", typeof(bool), typeof(CalculatorScientificOperators), new PropertyMetadata(false));
|
||||
DependencyProperty.Register(
|
||||
name: "IsErrorVisualState",
|
||||
propertyType: typeof(bool),
|
||||
ownerType: typeof(CalculatorScientificOperators),
|
||||
typeMetadata: new PropertyMetadata(
|
||||
defaultValue: false,
|
||||
propertyChangedCallback: (s, e) => (s as CalculatorScientificOperators)?.OnIsErrorVisualStatePropertyChanged(
|
||||
(bool)e.OldValue,
|
||||
(bool)e.NewValue
|
||||
)));
|
||||
|
||||
public bool IsWideLayout
|
||||
{
|
||||
|
|
|
@ -18,85 +18,99 @@ using Windows.UI.Xaml.Navigation;
|
|||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
public sealed partial class OperatorsPanel : UserControl
|
||||
{
|
||||
public sealed partial class OperatorsPanel : UserControl
|
||||
{
|
||||
|
||||
|
||||
public bool IsBitFlipChecked
|
||||
{
|
||||
get { return (bool)GetValue(IsBitFlipCheckedProperty); }
|
||||
set { SetValue(IsBitFlipCheckedProperty, value); }
|
||||
}
|
||||
public bool IsBitFlipChecked
|
||||
{
|
||||
get { return (bool)GetValue(IsBitFlipCheckedProperty); }
|
||||
set { SetValue(IsBitFlipCheckedProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsBitFlipCheckedProperty =
|
||||
DependencyProperty.Register("IsBitFlipChecked", typeof(bool), typeof(OperatorsPanel), new PropertyMetadata(false));
|
||||
public static readonly DependencyProperty IsBitFlipCheckedProperty =
|
||||
DependencyProperty.Register(
|
||||
name: "IsBitFlipChecked",
|
||||
propertyType: typeof(bool),
|
||||
ownerType: typeof(OperatorsPanel),
|
||||
typeMetadata: new PropertyMetadata(
|
||||
defaultValue: false,
|
||||
propertyChangedCallback: (s, e) => (s as OperatorsPanel)?.OnIsBitFlipCheckedPropertyChanged(
|
||||
oldValue: (bool)e.OldValue,
|
||||
newValue: (bool)e.NewValue)));
|
||||
|
||||
public bool IsErrorVisualState
|
||||
{
|
||||
get => (bool)GetValue(IsErrorVisualStateProperty);
|
||||
set => SetValue(IsErrorVisualStateProperty, value);
|
||||
}
|
||||
|
||||
// Using a DependencyProperty as the backing store for IsErrorVisualState. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty IsErrorVisualStateProperty =
|
||||
DependencyProperty.Register(
|
||||
name: "IsErrorVisualState",
|
||||
propertyType: typeof(bool),
|
||||
ownerType: typeof(OperatorsPanel),
|
||||
typeMetadata: new PropertyMetadata(
|
||||
defaultValue: false,
|
||||
propertyChangedCallback: (s, e) => (s as OperatorsPanel)?.OnIsErrorVisualStatePropertyChanged(
|
||||
oldValue: (bool)e.OldValue,
|
||||
newValue: (bool)e.NewValue)));
|
||||
|
||||
public bool IsErrorVisualState
|
||||
{
|
||||
get { return (bool)GetValue(IsErrorVisualStateProperty); }
|
||||
set { SetValue(IsErrorVisualStateProperty, value); }
|
||||
}
|
||||
public OperatorsPanel()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
// Using a DependencyProperty as the backing store for IsErrorVisualState. This enables animation, styling, binding, etc...
|
||||
public static readonly DependencyProperty IsErrorVisualStateProperty =
|
||||
DependencyProperty.Register("IsErrorVisualState", typeof(bool), typeof(OperatorsPanel), new PropertyMetadata(false));
|
||||
private StandardCalculatorViewModel Model => (CalculatorApp.ViewModel.StandardCalculatorViewModel)(this.DataContext);
|
||||
|
||||
public OperatorsPanel()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
private void OnIsBitFlipCheckedPropertyChanged(bool oldValue, bool newValue)
|
||||
{
|
||||
if (newValue)
|
||||
{
|
||||
EnsureProgrammerBitFlipPanel();
|
||||
}
|
||||
}
|
||||
|
||||
StandardCalculatorViewModel Model => (CalculatorApp.ViewModel.StandardCalculatorViewModel)(this.DataContext);
|
||||
private void OnIsErrorVisualStatePropertyChanged(bool oldValue, bool newValue)
|
||||
{
|
||||
if (Model.IsStandard)
|
||||
{
|
||||
StandardOperators.IsErrorVisualState = newValue;
|
||||
}
|
||||
else if (Model.IsScientific)
|
||||
{
|
||||
ScientificOperators.IsErrorVisualState = newValue;
|
||||
}
|
||||
else if (Model.IsProgrammer)
|
||||
{
|
||||
ProgrammerRadixOperators.IsErrorVisualState = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
void OnIsBitFlipCheckedPropertyChanged(bool oldValue, bool newValue)
|
||||
{
|
||||
if (newValue)
|
||||
{
|
||||
EnsureProgrammerBitFlipPanel();
|
||||
}
|
||||
}
|
||||
internal void EnsureScientificOps()
|
||||
{
|
||||
if (ScientificOperators == null)
|
||||
{
|
||||
this.FindName("ScientificOperators");
|
||||
}
|
||||
}
|
||||
|
||||
void OnIsErrorVisualStatePropertyChanged(bool oldValue, bool newValue)
|
||||
{
|
||||
if (Model.IsStandard)
|
||||
{
|
||||
StandardOperators.IsErrorVisualState = newValue;
|
||||
}
|
||||
else if (Model.IsScientific)
|
||||
{
|
||||
ScientificOperators.IsErrorVisualState = newValue;
|
||||
}
|
||||
else if (Model.IsProgrammer)
|
||||
{
|
||||
ProgrammerRadixOperators.IsErrorVisualState = newValue;
|
||||
}
|
||||
}
|
||||
internal void EnsureProgrammerRadixOps()
|
||||
{
|
||||
if (ProgrammerRadixOperators == null)
|
||||
{
|
||||
this.FindName("ProgrammerRadixOperators");
|
||||
}
|
||||
}
|
||||
|
||||
internal void EnsureScientificOps()
|
||||
{
|
||||
if (ScientificOperators == null)
|
||||
{
|
||||
this.FindName("ScientificOperators");
|
||||
}
|
||||
}
|
||||
internal void EnsureProgrammerBitFlipPanel()
|
||||
{
|
||||
if (BitFlipPanel == null)
|
||||
{
|
||||
this.FindName("BitFlipPanel");
|
||||
}
|
||||
}
|
||||
|
||||
internal void EnsureProgrammerRadixOps()
|
||||
{
|
||||
if (ProgrammerRadixOperators == null)
|
||||
{
|
||||
this.FindName("ProgrammerRadixOperators");
|
||||
}
|
||||
}
|
||||
|
||||
internal void EnsureProgrammerBitFlipPanel()
|
||||
{
|
||||
if (BitFlipPanel == null)
|
||||
{
|
||||
this.FindName("BitFlipPanel");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue