ViewModelProperties namespaces converted to static member properties. (#306)

This commit is contained in:
Daniel Belcher 2019-03-20 09:56:59 -07:00 committed by Stephanie Anderl
parent 4b6b8fa8fa
commit 3bff99b323
15 changed files with 142 additions and 183 deletions

View File

@ -32,14 +32,11 @@ using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Media;
namespace CalculatorApp::ViewModel::ApplicationViewModelProperties namespace
{ {
StringReference Mode(L"Mode"); StringReference CategoriesPropertyName(L"Categories");
StringReference PreviousMode(L"PreviousMode"); StringReference ClearMemoryVisibilityPropertyName(L"ClearMemoryVisibility");
StringReference ClearMemoryVisibility(L"ClearMemoryVisibility"); StringReference AppBarVisibilityPropertyName(L"AppBarVisibility");
StringReference AppBarVisibility(L"AppBarVisibility");
StringReference CategoryName(L"CategoryName");
StringReference Categories(L"Categories");
} }
ApplicationViewModel::ApplicationViewModel() : ApplicationViewModel::ApplicationViewModel() :
@ -60,7 +57,7 @@ void ApplicationViewModel::Mode::set(ViewMode value)
PreviousMode = m_mode; PreviousMode = m_mode;
m_mode = value; m_mode = value;
OnModeChanged(); OnModeChanged();
RaisePropertyChanged(ApplicationViewModelProperties::Mode); RaisePropertyChanged(ModePropertyName);
} }
} }
@ -69,7 +66,7 @@ void ApplicationViewModel::Categories::set(IObservableVector<NavCategoryGroup^>^
if (m_categories != value) if (m_categories != value)
{ {
m_categories = value; m_categories = value;
RaisePropertyChanged(ApplicationViewModelProperties::Categories); RaisePropertyChanged(CategoriesPropertyName);
} }
} }
@ -163,11 +160,11 @@ void ApplicationViewModel::OnModeChanged()
// //
// Save the changed mode, so that the new window launches in this mode. // Save the changed mode, so that the new window launches in this mode.
// Don't save until after we have adjusted to the new mode, so we don't save a mode that fails to load. // Don't save until after we have adjusted to the new mode, so we don't save a mode that fails to load.
ApplicationData::Current->LocalSettings->Values->Insert(ApplicationViewModelProperties::Mode, NavCategory::Serialize(m_mode)); ApplicationData::Current->LocalSettings->Values->Insert(ModePropertyName, NavCategory::Serialize(m_mode));
TraceLogger::GetInstance().LogModeChangeEnd(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread())); TraceLogger::GetInstance().LogModeChangeEnd(m_mode, ApplicationView::GetApplicationViewIdForWindow(CoreWindow::GetForCurrentThread()));
RaisePropertyChanged(ApplicationViewModelProperties::ClearMemoryVisibility); RaisePropertyChanged(ClearMemoryVisibilityPropertyName);
RaisePropertyChanged(ApplicationViewModelProperties::AppBarVisibility); RaisePropertyChanged(AppBarVisibilityPropertyName);
} }
void ApplicationViewModel::OnCopyCommand(Object^ parameter) void ApplicationViewModel::OnCopyCommand(Object^ parameter)

View File

@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved. // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. // Licensed under the MIT License.
#pragma once #pragma once
@ -11,16 +11,6 @@ namespace CalculatorApp
{ {
namespace ViewModel namespace ViewModel
{ {
namespace ApplicationViewModelProperties
{
extern Platform::StringReference Mode;
extern Platform::StringReference PreviousMode;
extern Platform::StringReference ClearMemoryVisibility;
extern Platform::StringReference AppBarVisibility;
extern Platform::StringReference CategoryName;
extern Platform::StringReference Categories;
}
[Windows::UI::Xaml::Data::Bindable] [Windows::UI::Xaml::Data::Bindable]
public ref class ApplicationViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged public ref class ApplicationViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
{ {
@ -32,9 +22,9 @@ namespace CalculatorApp
OBSERVABLE_OBJECT(); OBSERVABLE_OBJECT();
OBSERVABLE_PROPERTY_RW(StandardCalculatorViewModel^, CalculatorViewModel); OBSERVABLE_PROPERTY_RW(StandardCalculatorViewModel^, CalculatorViewModel);
OBSERVABLE_PROPERTY_RW(DateCalculatorViewModel^, DateCalcViewModel); OBSERVABLE_PROPERTY_RW(DateCalculatorViewModel^, DateCalcViewModel);
OBSERVABLE_PROPERTY_RW(CalculatorApp::ViewModel::UnitConverterViewModel^, ConverterViewModel); OBSERVABLE_PROPERTY_RW(UnitConverterViewModel^, ConverterViewModel);
OBSERVABLE_PROPERTY_RW(CalculatorApp::Common::ViewMode, PreviousMode); OBSERVABLE_PROPERTY_RW(CalculatorApp::Common::ViewMode, PreviousMode);
OBSERVABLE_PROPERTY_RW(Platform::String^, CategoryName); OBSERVABLE_NAMED_PROPERTY_RW(Platform::String^, CategoryName);
COMMAND_FOR_METHOD(CopyCommand, ApplicationViewModel::OnCopyCommand); COMMAND_FOR_METHOD(CopyCommand, ApplicationViewModel::OnCopyCommand);
COMMAND_FOR_METHOD(PasteCommand, ApplicationViewModel::OnPasteCommand); COMMAND_FOR_METHOD(PasteCommand, ApplicationViewModel::OnPasteCommand);
@ -48,6 +38,13 @@ namespace CalculatorApp
void set(CalculatorApp::Common::ViewMode value); void set(CalculatorApp::Common::ViewMode value);
} }
static property Platform::String^ ModePropertyName
{
Platform::String^ get()
{
return Platform::StringReference(L"Mode");
}
}
property Windows::Foundation::Collections::IObservableVector<CalculatorApp::Common::NavCategoryGroup^>^ Categories property Windows::Foundation::Collections::IObservableVector<CalculatorApp::Common::NavCategoryGroup^>^ Categories
{ {

View File

@ -42,10 +42,16 @@
}\ }\
} private: t m_##n; public: } private: t m_##n; public:
#define NAMED_OBSERVABLE_PROPERTY_RW(t, n)\ #define OBSERVABLE_NAMED_PROPERTY_R(t, n)\
OBSERVABLE_PROPERTY_R(t, n)\
internal: static property Platform::String^ n##PropertyName {\
Platform::String^ get() { return Platform::StringReference(L#n); }\
} public:
#define OBSERVABLE_NAMED_PROPERTY_RW(t, n)\
OBSERVABLE_PROPERTY_RW(t, n)\ OBSERVABLE_PROPERTY_RW(t, n)\
private: property Platform::StringReference n##_PropertyName {\ internal: static property Platform::String^ n##PropertyName {\
Platform::StringReference get() { return Platform::StringReference(L#n); }\ Platform::String^ get() { return Platform::StringReference(L#n); }\
} public: } public:
#define OBSERVABLE_PROPERTY_FIELD(n) m_##n #define OBSERVABLE_PROPERTY_FIELD(n) m_##n

View File

@ -22,14 +22,14 @@ using namespace Windows::Globalization;
using namespace Windows::Globalization::DateTimeFormatting; using namespace Windows::Globalization::DateTimeFormatting;
using namespace Windows::System::UserProfile; using namespace Windows::System::UserProfile;
namespace CalculatorApp::ViewModel::DateCalculatorViewModelProperties namespace
{ {
StringReference StrDateDiffResult(L"StrDateDiffResult"); StringReference StrDateDiffResultPropertyName(L"StrDateDiffResult");
StringReference StrDateDiffResultAutomationName(L"StrDateDiffResultAutomationName"); StringReference StrDateDiffResultAutomationNamePropertyName(L"StrDateDiffResultAutomationName");
StringReference StrDateDiffResultInDays(L"StrDateDiffResultInDays"); StringReference StrDateDiffResultInDaysPropertyName(L"StrDateDiffResultInDays");
StringReference StrDateResult(L"StrDateResult"); StringReference StrDateResultPropertyName(L"StrDateResult");
StringReference StrDateResultAutomationName(L"StrDateResultAutomationName"); StringReference StrDateResultAutomationNamePropertyName(L"StrDateResultAutomationName");
StringReference IsDiffInDays(L"IsDiffInDays"); StringReference IsDiffInDaysPropertyName(L"IsDiffInDays");
} }
DateCalculatorViewModel::DateCalculatorViewModel() : DateCalculatorViewModel::DateCalculatorViewModel() :
@ -97,18 +97,18 @@ DateCalculatorViewModel::DateCalculatorViewModel() :
void DateCalculatorViewModel::OnPropertyChanged(_In_ String^ prop) void DateCalculatorViewModel::OnPropertyChanged(_In_ String^ prop)
{ {
if (prop == DateCalculatorViewModelProperties::StrDateDiffResult) if (prop == StrDateDiffResultPropertyName)
{ {
UpdateStrDateDiffResultAutomationName(); UpdateStrDateDiffResultAutomationName();
} }
else if (prop == DateCalculatorViewModelProperties::StrDateResult) else if (prop == StrDateResultPropertyName)
{ {
UpdateStrDateResultAutomationName(); UpdateStrDateResultAutomationName();
} }
else if (prop != DateCalculatorViewModelProperties::StrDateDiffResultAutomationName else if (prop != StrDateDiffResultAutomationNamePropertyName
&& prop != DateCalculatorViewModelProperties::StrDateDiffResultInDays && prop != StrDateDiffResultInDaysPropertyName
&& prop != DateCalculatorViewModelProperties::StrDateResultAutomationName && prop != StrDateResultAutomationNamePropertyName
&& prop != DateCalculatorViewModelProperties::IsDiffInDays) && prop != IsDiffInDaysPropertyName)
{ {
OnInputsChanged(); OnInputsChanged();
} }

View File

@ -30,40 +30,34 @@ constexpr int StandardModePrecision = 16;
constexpr int ScientificModePrecision = 32; constexpr int ScientificModePrecision = 32;
constexpr int ProgrammerModePrecision = 64; constexpr int ProgrammerModePrecision = 64;
namespace CalculatorApp::ViewModel namespace
{ {
namespace CalculatorViewModelProperties StringReference IsStandardPropertyName(L"IsStandard");
{ StringReference IsScientificPropertyName(L"IsScientific");
StringReference IsMemoryEmpty(L"IsMemoryEmpty"); StringReference IsProgrammerPropertyName(L"IsProgrammer");
StringReference IsScientific(L"IsScientific"); StringReference DisplayValuePropertyName(L"DisplayValue");
StringReference IsStandard(L"IsStandard"); StringReference CalculationResultAutomationNamePropertyName(L"CalculationResultAutomationName");
StringReference IsProgrammer(L"IsProgrammer"); }
StringReference DisplayValue(L"DisplayValue");
StringReference IsInError(L"IsInError");
StringReference BinaryDisplayValue(L"BinaryDisplayValue");
StringReference OpenParenthesisCount(L"OpenParenthesisCount");
}
namespace CalculatorResourceKeys namespace CalculatorResourceKeys
{ {
StringReference CalculatorExpression(L"Format_CalculatorExpression"); StringReference CalculatorExpression(L"Format_CalculatorExpression");
StringReference CalculatorResults(L"Format_CalculatorResults"); StringReference CalculatorResults(L"Format_CalculatorResults");
StringReference CalculatorResults_DecimalSeparator_Announced(L"Format_CalculatorResults_Decimal"); StringReference CalculatorResults_DecimalSeparator_Announced(L"Format_CalculatorResults_Decimal");
StringReference HexButton(L"Format_HexButtonValue"); StringReference HexButton(L"Format_HexButtonValue");
StringReference DecButton(L"Format_DecButtonValue"); StringReference DecButton(L"Format_DecButtonValue");
StringReference OctButton(L"Format_OctButtonValue"); StringReference OctButton(L"Format_OctButtonValue");
StringReference BinButton(L"Format_BinButtonValue"); StringReference BinButton(L"Format_BinButtonValue");
StringReference LeftParenthesisAutomationFormat(L"Format_OpenParenthesisAutomationNamePrefix"); StringReference LeftParenthesisAutomationFormat(L"Format_OpenParenthesisAutomationNamePrefix");
StringReference OpenParenthesisCountAutomationFormat(L"Format_OpenParenthesisCountAutomationNamePrefix"); StringReference OpenParenthesisCountAutomationFormat(L"Format_OpenParenthesisCountAutomationNamePrefix");
StringReference NoParenthesisAdded(L"NoRightParenthesisAdded_Announcement"); StringReference NoParenthesisAdded(L"NoRightParenthesisAdded_Announcement");
StringReference MaxDigitsReachedFormat(L"Format_MaxDigitsReached"); StringReference MaxDigitsReachedFormat(L"Format_MaxDigitsReached");
StringReference ButtonPressFeedbackFormat(L"Format_ButtonPressAuditoryFeedback"); StringReference ButtonPressFeedbackFormat(L"Format_ButtonPressAuditoryFeedback");
StringReference MemorySave(L"Format_MemorySave"); StringReference MemorySave(L"Format_MemorySave");
StringReference MemoryItemChanged(L"Format_MemorySlotChanged"); StringReference MemoryItemChanged(L"Format_MemorySlotChanged");
StringReference MemoryItemCleared(L"Format_MemorySlotCleared"); StringReference MemoryItemCleared(L"Format_MemorySlotCleared");
StringReference MemoryCleared(L"Memory_Cleared"); StringReference MemoryCleared(L"Memory_Cleared");
StringReference DisplayCopied(L"Display_Copied"); StringReference DisplayCopied(L"Display_Copied");
}
} }
StandardCalculatorViewModel::StandardCalculatorViewModel() : StandardCalculatorViewModel::StandardCalculatorViewModel() :
@ -1276,30 +1270,30 @@ void StandardCalculatorViewModel::Deserialize(Array<unsigned char>^ state)
void StandardCalculatorViewModel::OnPropertyChanged(String^ propertyname) void StandardCalculatorViewModel::OnPropertyChanged(String^ propertyname)
{ {
if (propertyname == CalculatorViewModelProperties::IsScientific) if (propertyname == IsScientificPropertyName)
{ {
if (IsScientific) if (IsScientific)
{ {
OnButtonPressed(NumbersAndOperatorsEnum::IsScientificMode); OnButtonPressed(NumbersAndOperatorsEnum::IsScientificMode);
} }
} }
else if (propertyname == CalculatorViewModelProperties::IsProgrammer) else if (propertyname == IsProgrammerPropertyName)
{ {
if (IsProgrammer) if (IsProgrammer)
{ {
OnButtonPressed(NumbersAndOperatorsEnum::IsProgrammerMode); OnButtonPressed(NumbersAndOperatorsEnum::IsProgrammerMode);
} }
} }
else if (propertyname == CalculatorViewModelProperties::IsStandard) else if (propertyname == IsStandardPropertyName)
{ {
if (IsStandard) if (IsStandard)
{ {
OnButtonPressed(NumbersAndOperatorsEnum::IsStandardMode); OnButtonPressed(NumbersAndOperatorsEnum::IsStandardMode);
} }
} }
else if (propertyname == CalculatorViewModelProperties::DisplayValue) else if (propertyname == DisplayValuePropertyName)
{ {
RaisePropertyChanged(CalculationResultAutomationName_PropertyName); RaisePropertyChanged(CalculationResultAutomationNamePropertyName);
Announcement = GetDisplayUpdatedNarratorAnnouncement(); Announcement = GetDisplayUpdatedNarratorAnnouncement();
} }
} }

View File

@ -31,13 +31,6 @@ namespace CalculatorApp
#define ASCII_0 48 #define ASCII_0 48
public delegate void HideMemoryClickedHandler(); public delegate void HideMemoryClickedHandler();
public delegate void ProgModeRadixChangeHandler(); public delegate void ProgModeRadixChangeHandler();
namespace CalculatorViewModelProperties
{
extern Platform::StringReference IsMemoryEmpty;
extern Platform::StringReference IsInError;
extern Platform::StringReference BinaryDisplayValue;
extern Platform::StringReference OpenParenthesisCount;
}
[Windows::UI::Xaml::Data::Bindable] [Windows::UI::Xaml::Data::Bindable]
public ref class StandardCalculatorViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged public ref class StandardCalculatorViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
@ -52,14 +45,14 @@ namespace CalculatorApp
OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged); OBSERVABLE_OBJECT_CALLBACK(OnPropertyChanged);
OBSERVABLE_PROPERTY_RW(Platform::String^, DisplayValue); OBSERVABLE_PROPERTY_RW(Platform::String^, DisplayValue);
OBSERVABLE_PROPERTY_RW(HistoryViewModel^, HistoryVM); OBSERVABLE_PROPERTY_RW(HistoryViewModel^, HistoryVM);
OBSERVABLE_PROPERTY_RW(bool, IsInError); OBSERVABLE_NAMED_PROPERTY_RW(bool, IsInError);
OBSERVABLE_PROPERTY_RW(bool, IsOperatorCommand); OBSERVABLE_PROPERTY_RW(bool, IsOperatorCommand);
OBSERVABLE_PROPERTY_RW(Platform::String^, DisplayStringExpression); OBSERVABLE_PROPERTY_RW(Platform::String^, DisplayStringExpression);
OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IVector<Common::DisplayExpressionToken^>^, ExpressionTokens); OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IVector<Common::DisplayExpressionToken^>^, ExpressionTokens);
OBSERVABLE_PROPERTY_RW(Platform::String^, DecimalDisplayValue); OBSERVABLE_PROPERTY_RW(Platform::String^, DecimalDisplayValue);
OBSERVABLE_PROPERTY_RW(Platform::String^, HexDisplayValue); OBSERVABLE_PROPERTY_RW(Platform::String^, HexDisplayValue);
OBSERVABLE_PROPERTY_RW(Platform::String^, OctalDisplayValue); OBSERVABLE_PROPERTY_RW(Platform::String^, OctalDisplayValue);
OBSERVABLE_PROPERTY_RW(Platform::String^, BinaryDisplayValue); OBSERVABLE_NAMED_PROPERTY_RW(Platform::String^, BinaryDisplayValue);
OBSERVABLE_PROPERTY_RW(Platform::String^, HexDisplayValue_AutomationName); OBSERVABLE_PROPERTY_RW(Platform::String^, HexDisplayValue_AutomationName);
OBSERVABLE_PROPERTY_RW(Platform::String^, DecDisplayValue_AutomationName); OBSERVABLE_PROPERTY_RW(Platform::String^, DecDisplayValue_AutomationName);
OBSERVABLE_PROPERTY_RW(Platform::String^, OctDisplayValue_AutomationName); OBSERVABLE_PROPERTY_RW(Platform::String^, OctDisplayValue_AutomationName);
@ -70,19 +63,19 @@ namespace CalculatorApp
OBSERVABLE_PROPERTY_RW(bool, IsDecimalEnabled); OBSERVABLE_PROPERTY_RW(bool, IsDecimalEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsCurrentViewPinned); OBSERVABLE_PROPERTY_RW(bool, IsCurrentViewPinned);
OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IVector<MemoryItemViewModel^>^, MemorizedNumbers); OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IVector<MemoryItemViewModel^>^, MemorizedNumbers);
OBSERVABLE_PROPERTY_RW(bool, IsMemoryEmpty); OBSERVABLE_NAMED_PROPERTY_RW(bool, IsMemoryEmpty);
OBSERVABLE_PROPERTY_RW(bool, IsFToEChecked); OBSERVABLE_PROPERTY_RW(bool, IsFToEChecked);
OBSERVABLE_PROPERTY_RW(bool, IsFToEEnabled); OBSERVABLE_PROPERTY_RW(bool, IsFToEEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsHyperbolicChecked); OBSERVABLE_PROPERTY_RW(bool, IsHyperbolicChecked);
OBSERVABLE_PROPERTY_RW(bool, AreHEXButtonsEnabled); OBSERVABLE_PROPERTY_RW(bool, AreHEXButtonsEnabled);
NAMED_OBSERVABLE_PROPERTY_RW(Platform::String^, CalculationResultAutomationName); OBSERVABLE_PROPERTY_RW(Platform::String^, CalculationResultAutomationName);
NAMED_OBSERVABLE_PROPERTY_RW(Platform::String^, CalculationExpressionAutomationName); OBSERVABLE_PROPERTY_RW(Platform::String^, CalculationExpressionAutomationName);
OBSERVABLE_PROPERTY_RW(bool, IsShiftProgrammerChecked); OBSERVABLE_PROPERTY_RW(bool, IsShiftProgrammerChecked);
OBSERVABLE_PROPERTY_RW(bool, IsQwordEnabled); OBSERVABLE_PROPERTY_RW(bool, IsQwordEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsDwordEnabled); OBSERVABLE_PROPERTY_RW(bool, IsDwordEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsWordEnabled); OBSERVABLE_PROPERTY_RW(bool, IsWordEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsByteEnabled); OBSERVABLE_PROPERTY_RW(bool, IsByteEnabled);
OBSERVABLE_PROPERTY_RW(Platform::String^, OpenParenthesisCount); OBSERVABLE_NAMED_PROPERTY_RW(Platform::String^, OpenParenthesisCount);
OBSERVABLE_PROPERTY_RW(int, CurrentRadixType); OBSERVABLE_PROPERTY_RW(int, CurrentRadixType);
OBSERVABLE_PROPERTY_RW(bool, AreTokensUpdated); OBSERVABLE_PROPERTY_RW(bool, AreTokensUpdated);
OBSERVABLE_PROPERTY_RW(bool, AreHistoryShortcutsEnabled); OBSERVABLE_PROPERTY_RW(bool, AreHistoryShortcutsEnabled);

View File

@ -56,47 +56,37 @@ constexpr unsigned int CONVERSION_FINALIZED_DELAY_IN_MS = 1000;
const wregex regexTrimSpacesStart = wregex(L"^\\s+"); const wregex regexTrimSpacesStart = wregex(L"^\\s+");
const wregex regexTrimSpacesEnd = wregex(L"\\s+$"); const wregex regexTrimSpacesEnd = wregex(L"\\s+$");
namespace CalculatorApp::ViewModel namespace
{ {
namespace UnitConverterViewModelProperties StringReference CurrentCategoryPropertyName(L"CurrentCategory");
{ StringReference Unit1AutomationNamePropertyName(L"Unit1AutomationName");
StringReference CurrentCategory(L"CurrentCategory"); StringReference Unit2AutomationNamePropertyName(L"Unit2AutomationName");
StringReference Unit1(L"Unit1"); StringReference Unit1PropertyName(L"Unit1");
StringReference Unit2(L"Unit2"); StringReference Unit2PropertyName(L"Unit2");
StringReference Value1Active(L"Value1Active"); StringReference Value1PropertyName(L"Value1");
StringReference Value2Active(L"Value2Active"); StringReference Value2PropertyName(L"Value2");
StringReference Value1(L"Value1"); StringReference Value1ActivePropertyName(L"Value1Active");
StringReference Value2(L"Value2"); StringReference Value2ActivePropertyName(L"Value2Active");
StringReference Value1AutomationName(L"Value1AutomationName"); StringReference Value1AutomationNamePropertyName(L"Value1AutomationName");
StringReference Value2AutomationName(L"Value2AutomationName"); StringReference Value2AutomationNamePropertyName(L"Value2AutomationName");
StringReference SupplementaryVisibility(L"SupplementaryVisibility"); StringReference CurrencySymbol1PropertyName(L"CurrencySymbol1");
StringReference SupplementaryResults(L"SupplementaryResults"); StringReference CurrencySymbol2PropertyName(L"CurrencySymbol2");
StringReference Unit1AutomationName(L"Unit1AutomationName"); StringReference CurrencySymbolVisibilityPropertyName(L"CurrencySymbolVisibility");
StringReference Unit2AutomationName(L"Unit2AutomationName"); StringReference SupplementaryVisibilityPropertyName(L"SupplementaryVisibility");
StringReference CurrencySymbol1(L"CurrencySymbol1"); }
StringReference CurrencySymbol2(L"CurrencySymbol2");
StringReference CurrencySymbolVisibility(L"CurrencySymbolVisibility");
StringReference CurrencyRatioEquality(L"CurrencyRatioEquality");
StringReference CurrencyRatioEqualityAutomationName(L"CurrencyRatioEqualityAutomationName");
StringReference NetworkBehavior(L"NetworkBehavior");
StringReference CurrencyDataLoadFailed(L"CurrencyDataLoadFailed");
StringReference CurrencyDataIsWeekOld(L"CurrencyDataIsWeekOld");
StringReference IsCurrencyLoadingVisible(L"IsCurrencyLoadingVisible");
}
namespace UnitConverterResourceKeys namespace CalculatorApp::ViewModel::UnitConverterResourceKeys
{ {
StringReference ValueFromFormat(L"Format_ValueFrom"); StringReference ValueFromFormat(L"Format_ValueFrom");
StringReference ValueFromDecimalFormat(L"Format_ValueFrom_Decimal"); StringReference ValueFromDecimalFormat(L"Format_ValueFrom_Decimal");
StringReference ValueToFormat(L"Format_ValueTo"); StringReference ValueToFormat(L"Format_ValueTo");
StringReference ConversionResultFormat(L"Format_ConversionResult"); StringReference ConversionResultFormat(L"Format_ConversionResult");
StringReference InputUnit_Name(L"InputUnit_Name"); StringReference InputUnit_Name(L"InputUnit_Name");
StringReference OutputUnit_Name(L"OutputUnit_Name"); StringReference OutputUnit_Name(L"OutputUnit_Name");
StringReference MaxDigitsReachedFormat(L"Format_MaxDigitsReached"); StringReference MaxDigitsReachedFormat(L"Format_MaxDigitsReached");
StringReference UpdatingCurrencyRates(L"UpdatingCurrencyRates"); StringReference UpdatingCurrencyRates(L"UpdatingCurrencyRates");
StringReference CurrencyRatesUpdated(L"CurrencyRatesUpdated"); StringReference CurrencyRatesUpdated(L"CurrencyRatesUpdated");
StringReference CurrencyRatesUpdateFailed(L"CurrencyRatesUpdateFailed"); StringReference CurrencyRatesUpdateFailed(L"CurrencyRatesUpdateFailed");
}
} }
UnitConverterViewModel::UnitConverterViewModel(const shared_ptr<UCM::IUnitConverter>& model) : UnitConverterViewModel::UnitConverterViewModel(const shared_ptr<UCM::IUnitConverter>& model) :
@ -281,8 +271,8 @@ void UnitConverterViewModel::OnSwitchActive(Platform::Object^ unused)
Utils::Swap(&m_localizedValueFromFormat, &m_localizedValueToFormat); Utils::Swap(&m_localizedValueFromFormat, &m_localizedValueToFormat);
Utils::Swap(&m_Unit1AutomationName, &m_Unit2AutomationName); Utils::Swap(&m_Unit1AutomationName, &m_Unit2AutomationName);
RaisePropertyChanged(UnitConverterViewModelProperties::Unit1AutomationName); RaisePropertyChanged(Unit1AutomationNamePropertyName);
RaisePropertyChanged(UnitConverterViewModelProperties::Unit2AutomationName); RaisePropertyChanged(Unit2AutomationNamePropertyName);
m_isInputBlocked = false; m_isInputBlocked = false;
m_model->SwitchActive(m_valueFromUnlocalized); m_model->SwitchActive(m_valueFromUnlocalized);
@ -561,13 +551,13 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop)
{ {
static bool isCategoryChanging = false; static bool isCategoryChanging = false;
if (prop->Equals(UnitConverterViewModelProperties::CurrentCategory)) if (prop == CurrentCategoryPropertyName)
{ {
isCategoryChanging = true; isCategoryChanging = true;
CategoryChanged->Execute(nullptr); CategoryChanged->Execute(nullptr);
isCategoryChanging = false; isCategoryChanging = false;
} }
else if (prop->Equals(UnitConverterViewModelProperties::Unit1) || prop->Equals(UnitConverterViewModelProperties::Unit2)) else if (prop == Unit1PropertyName || prop == Unit2PropertyName)
{ {
// Category changes will handle updating units after they've both been updated. // Category changes will handle updating units after they've both been updated.
// This event should only be used to update units from explicit user interaction. // This event should only be used to update units from explicit user interaction.
@ -576,7 +566,7 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop)
UnitChanged->Execute(nullptr); UnitChanged->Execute(nullptr);
} }
// Get the localized automation name for each CalculationResults field // Get the localized automation name for each CalculationResults field
if (prop->Equals(UnitConverterViewModelProperties::Unit1)) if (prop == Unit1PropertyName)
{ {
UpdateValue1AutomationName(); UpdateValue1AutomationName();
} }
@ -585,15 +575,15 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop)
UpdateValue2AutomationName(); UpdateValue2AutomationName();
} }
} }
else if (prop->Equals(UnitConverterViewModelProperties::Value1)) else if (prop == Value1PropertyName)
{ {
UpdateValue1AutomationName(); UpdateValue1AutomationName();
} }
else if (prop->Equals(UnitConverterViewModelProperties::Value2)) else if (prop == Value2PropertyName)
{ {
UpdateValue2AutomationName(); UpdateValue2AutomationName();
} }
else if (prop->Equals(UnitConverterViewModelProperties::Value1Active) || prop->Equals(UnitConverterViewModelProperties::Value2Active)) else if (prop == Value1ActivePropertyName || prop == Value2ActivePropertyName)
{ {
// if one of the values is activated, and as a result both are true, it means // if one of the values is activated, and as a result both are true, it means
// that we're trying to switch. // that we're trying to switch.
@ -605,11 +595,11 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop)
UpdateValue1AutomationName(); UpdateValue1AutomationName();
UpdateValue2AutomationName(); UpdateValue2AutomationName();
} }
else if (prop->Equals(UnitConverterViewModelProperties::SupplementaryResults)) else if (prop == SupplementaryResultsPropertyName)
{ {
RaisePropertyChanged(UnitConverterViewModelProperties::SupplementaryVisibility); RaisePropertyChanged(SupplementaryVisibilityPropertyName);
} }
else if (prop->Equals(UnitConverterViewModelProperties::Value1AutomationName)) else if (prop == Value1AutomationNamePropertyName)
{ {
m_isValue1Updating = false; m_isValue1Updating = false;
if (!m_isValue2Updating) if (!m_isValue2Updating)
@ -617,7 +607,7 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop)
AnnounceConversionResult(); AnnounceConversionResult();
} }
} }
else if (prop->Equals(UnitConverterViewModelProperties::Value2AutomationName)) else if (prop == Value2AutomationNamePropertyName)
{ {
m_isValue2Updating = false; m_isValue2Updating = false;
if (!m_isValue1Updating) if (!m_isValue1Updating)
@ -625,9 +615,9 @@ void UnitConverterViewModel::OnPropertyChanged(Platform::String^ prop)
AnnounceConversionResult(); AnnounceConversionResult();
} }
} }
else if (prop->Equals(UnitConverterViewModelProperties::CurrencySymbol1) || prop->Equals(UnitConverterViewModelProperties::CurrencySymbol2)) else if (prop == CurrencySymbol1PropertyName || prop == CurrencySymbol2PropertyName)
{ {
RaisePropertyChanged(UnitConverterViewModelProperties::CurrencySymbolVisibility); RaisePropertyChanged(CurrencySymbolVisibilityPropertyName);
} }
} }
@ -852,7 +842,7 @@ void UnitConverterViewModel::RefreshSupplementaryResults()
} }
m_cacheMutex.unlock(); m_cacheMutex.unlock();
RaisePropertyChanged(UnitConverterViewModelProperties::SupplementaryResults); RaisePropertyChanged(SupplementaryResultsPropertyName);
//EventWriteConverterSupplementaryResultsUpdated(); //EventWriteConverterSupplementaryResultsUpdated();
} }

View File

@ -138,25 +138,6 @@ namespace CalculatorApp
return ref new Activatable<TActivatable>(activatable); return ref new Activatable<TActivatable>(activatable);
} }
namespace UnitConverterViewModelProperties
{
extern Platform::StringReference CurrentCategory;
extern Platform::StringReference Unit1;
extern Platform::StringReference Unit2;
extern Platform::StringReference Value1Active;
extern Platform::StringReference Value2Active;
extern Platform::StringReference SupplementaryVisibility;
extern Platform::StringReference SupplementaryResults;
extern Platform::StringReference CurrencySymbol1;
extern Platform::StringReference CurrencySymbol2;
extern Platform::StringReference CurrencySymbolVisibility;
extern Platform::StringReference CurrencyRatioEquality;
extern Platform::StringReference NetworkBehavior;
extern Platform::StringReference CurrencyDataLoadFailed;
extern Platform::StringReference CurrencyDataIsWeekOld;
extern Platform::StringReference IsCurrencyLoadingVisible;
}
[Windows::UI::Xaml::Data::Bindable] [Windows::UI::Xaml::Data::Bindable]
public ref class UnitConverterViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged public ref class UnitConverterViewModel sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
{ {
@ -176,7 +157,7 @@ namespace CalculatorApp
OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencySymbol2); OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencySymbol2);
OBSERVABLE_PROPERTY_RW(Unit^, Unit2); OBSERVABLE_PROPERTY_RW(Unit^, Unit2);
OBSERVABLE_PROPERTY_RW(Platform::String^, Value2); OBSERVABLE_PROPERTY_RW(Platform::String^, Value2);
OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector<SupplementaryResult^>^, SupplementaryResults); OBSERVABLE_NAMED_PROPERTY_R(Windows::Foundation::Collections::IObservableVector<SupplementaryResult^>^, SupplementaryResults);
OBSERVABLE_PROPERTY_RW(bool, Value1Active); OBSERVABLE_PROPERTY_RW(bool, Value1Active);
OBSERVABLE_PROPERTY_RW(bool, Value2Active); OBSERVABLE_PROPERTY_RW(bool, Value2Active);
OBSERVABLE_PROPERTY_RW(Platform::String^, Value1AutomationName); OBSERVABLE_PROPERTY_RW(Platform::String^, Value1AutomationName);
@ -187,14 +168,14 @@ namespace CalculatorApp
OBSERVABLE_PROPERTY_RW(bool, IsDecimalEnabled); OBSERVABLE_PROPERTY_RW(bool, IsDecimalEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsDropDownOpen); OBSERVABLE_PROPERTY_RW(bool, IsDropDownOpen);
OBSERVABLE_PROPERTY_RW(bool, IsDropDownEnabled); OBSERVABLE_PROPERTY_RW(bool, IsDropDownEnabled);
OBSERVABLE_PROPERTY_RW(bool, IsCurrencyLoadingVisible); OBSERVABLE_NAMED_PROPERTY_RW(bool, IsCurrencyLoadingVisible);
OBSERVABLE_PROPERTY_RW(bool, IsCurrencyCurrentCategory); OBSERVABLE_PROPERTY_RW(bool, IsCurrencyCurrentCategory);
OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencyRatioEquality); OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencyRatioEquality);
OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencyRatioEqualityAutomationName); OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencyRatioEqualityAutomationName);
OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencyTimestamp); OBSERVABLE_PROPERTY_RW(Platform::String^, CurrencyTimestamp);
OBSERVABLE_PROPERTY_RW(CalculatorApp::NetworkAccessBehavior, NetworkBehavior); OBSERVABLE_NAMED_PROPERTY_RW(CalculatorApp::NetworkAccessBehavior, NetworkBehavior);
OBSERVABLE_PROPERTY_RW(bool, CurrencyDataLoadFailed); OBSERVABLE_NAMED_PROPERTY_RW(bool, CurrencyDataLoadFailed);
OBSERVABLE_PROPERTY_RW(bool, CurrencyDataIsWeekOld); OBSERVABLE_NAMED_PROPERTY_RW(bool, CurrencyDataIsWeekOld);
property Windows::UI::Xaml::Visibility SupplementaryVisibility property Windows::UI::Xaml::Visibility SupplementaryVisibility
{ {

View File

@ -389,11 +389,11 @@ void Calculator::EnsureProgrammer()
void Calculator::OnCalcPropertyChanged(_In_ Object^ sender, _In_ PropertyChangedEventArgs^ e) void Calculator::OnCalcPropertyChanged(_In_ Object^ sender, _In_ PropertyChangedEventArgs^ e)
{ {
String^ prop = e->PropertyName; String^ prop = e->PropertyName;
if (e->PropertyName->Equals(CalculatorViewModelProperties::IsMemoryEmpty)) if (prop == StandardCalculatorViewModel::IsMemoryEmptyPropertyName)
{ {
UpdateMemoryState(); UpdateMemoryState();
} }
else if (e->PropertyName->Equals(CalculatorViewModelProperties::IsInError)) else if (prop == StandardCalculatorViewModel::IsInErrorPropertyName)
{ {
OnIsInErrorPropertyChanged(); OnIsInErrorPropertyChanged();
} }

View File

@ -68,7 +68,7 @@ void CalculatorProgrammerBitFlipPanel::UnsubscribePropertyChanged()
void CalculatorProgrammerBitFlipPanel::OnPropertyChanged(Object^ sender, PropertyChangedEventArgs^ e) void CalculatorProgrammerBitFlipPanel::OnPropertyChanged(Object^ sender, PropertyChangedEventArgs^ e)
{ {
if (e->PropertyName == CalculatorViewModelProperties::BinaryDisplayValue) if (e->PropertyName == StandardCalculatorViewModel::BinaryDisplayValuePropertyName)
{ {
UpdateCheckedStates(); UpdateCheckedStates();
} }

View File

@ -102,7 +102,7 @@ void CalculatorProgrammerRadixOperators::IsErrorVisualState::set(bool value)
void CalculatorProgrammerRadixOperators::OnViewModelPropertyChanged(Object^ sender, PropertyChangedEventArgs^ e) void CalculatorProgrammerRadixOperators::OnViewModelPropertyChanged(Object^ sender, PropertyChangedEventArgs^ e)
{ {
if (e->PropertyName == CalculatorViewModelProperties::OpenParenthesisCount && closeParenthesisButton->FocusState != ::FocusState::Unfocused) if (e->PropertyName == StandardCalculatorViewModel::OpenParenthesisCountPropertyName && closeParenthesisButton->FocusState != ::FocusState::Unfocused)
{ {
Model->SetOpenParenthesisCountNarratorAnnouncement(); Model->SetOpenParenthesisCountNarratorAnnouncement();
} }

View File

@ -109,7 +109,7 @@ void CalculatorScientificOperators::SetOperatorRowVisibility()
void CalculatorScientificOperators::OnViewModelPropertyChanged(Object^ sender, PropertyChangedEventArgs^ e) void CalculatorScientificOperators::OnViewModelPropertyChanged(Object^ sender, PropertyChangedEventArgs^ e)
{ {
if (e->PropertyName == CalculatorViewModelProperties::OpenParenthesisCount && closeParenthesisButton->FocusState != ::FocusState::Unfocused) if (e->PropertyName == StandardCalculatorViewModel::OpenParenthesisCountPropertyName && closeParenthesisButton->FocusState != ::FocusState::Unfocused)
{ {
Model->SetOpenParenthesisCountNarratorAnnouncement(); Model->SetOpenParenthesisCountNarratorAnnouncement();
} }

View File

@ -105,9 +105,9 @@ void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
else else
{ {
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings; ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
if (localSettings->Values->HasKey(ApplicationViewModelProperties::Mode)) if (localSettings->Values->HasKey(ApplicationViewModel::ModePropertyName))
{ {
initialMode = NavCategory::Deserialize(localSettings->Values->Lookup(ApplicationViewModelProperties::Mode)); initialMode = NavCategory::Deserialize(localSettings->Values->Lookup(ApplicationViewModel::ModePropertyName));
} }
} }
@ -122,7 +122,8 @@ void MainPage::WindowSizeChanged(_In_ Platform::Object^ /*sender*/, _In_ Windows
void MainPage::OnAppPropertyChanged(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e) void MainPage::OnAppPropertyChanged(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e)
{ {
if (e->PropertyName->Equals(ApplicationViewModelProperties::Mode)) String^ propertyName = e->PropertyName;
if (propertyName == ApplicationViewModel::ModePropertyName)
{ {
ViewMode newValue = m_model->Mode; ViewMode newValue = m_model->Mode;
ViewMode previousMode = m_model->PreviousMode; ViewMode previousMode = m_model->PreviousMode;
@ -186,7 +187,7 @@ void MainPage::OnAppPropertyChanged(_In_ Platform::Object^ sender, _In_ Windows:
SetTitleBarControlColors(); SetTitleBarControlColors();
SetDefaultFocus(); SetDefaultFocus();
} }
else if (e->PropertyName->Equals(ApplicationViewModelProperties::CategoryName)) else if (propertyName == ApplicationViewModel::CategoryNamePropertyName)
{ {
SetHeaderAutomationName(); SetHeaderAutomationName();
AnnounceCategoryName(); AnnounceCategoryName();

View File

@ -95,7 +95,7 @@ void SupplementaryResults::OnLoaded(Object^ sender, RoutedEventArgs^ e)
void SupplementaryResults::OnConverterPropertyChanged(Object^ /*sender*/, PropertyChangedEventArgs^ e) void SupplementaryResults::OnConverterPropertyChanged(Object^ /*sender*/, PropertyChangedEventArgs^ e)
{ {
if (e->PropertyName == UnitConverterViewModelProperties::SupplementaryResults) if (e->PropertyName == UnitConverterViewModel::SupplementaryResultsPropertyName)
{ {
RefreshData(); RefreshData();
} }

View File

@ -82,16 +82,16 @@ UnitConverter::UnitConverter() :
void UnitConverter::OnPropertyChanged(_In_ Object^ sender, _In_ PropertyChangedEventArgs^ e) void UnitConverter::OnPropertyChanged(_In_ Object^ sender, _In_ PropertyChangedEventArgs^ e)
{ {
String^ propertyName = e->PropertyName; String^ propertyName = e->PropertyName;
if (propertyName->Equals(UnitConverterViewModelProperties::NetworkBehavior) || if (propertyName == UnitConverterViewModel::NetworkBehaviorPropertyName ||
propertyName->Equals(UnitConverterViewModelProperties::CurrencyDataLoadFailed)) propertyName == UnitConverterViewModel::CurrencyDataLoadFailedPropertyName)
{ {
OnNetworkBehaviorChanged(); OnNetworkBehaviorChanged();
} }
else if (propertyName->Equals(UnitConverterViewModelProperties::CurrencyDataIsWeekOld)) else if (propertyName == UnitConverterViewModel::CurrencyDataIsWeekOldPropertyName)
{ {
SetCurrencyTimestampFontWeight(); SetCurrencyTimestampFontWeight();
} }
else if (propertyName->Equals(UnitConverterViewModelProperties::IsCurrencyLoadingVisible)) else if (propertyName == UnitConverterViewModel::IsCurrencyLoadingVisiblePropertyName)
{ {
OnIsDisplayVisibleChanged(); OnIsDisplayVisibleChanged();
} }