Reverted textblock callback changes and added an event handler for when the radio buttons are checked.

This commit is contained in:
Stephanie Anderl 2019-03-04 10:46:01 -08:00
commit 31ee0eb659
3 changed files with 33 additions and 9 deletions

View file

@ -1,7 +1,6 @@
<UserControl x:Class="CalculatorApp.DateCalculator"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:automation="using:CalculatorApp.Common.Automation"
xmlns:controls="using:CalculatorApp.Controls"
xmlns:converters="using:CalculatorApp.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@ -429,6 +428,7 @@
Style="{StaticResource DateCalculation_CalendarPickerStyle}"
AutomationProperties.LabeledBy="{x:Bind Date_FromLabel}"
CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}"
Closed="CalendarFlyoutClosed"
DateChanged="FromDate_DateChanged"/>
<!-- To Date -->
@ -444,6 +444,7 @@
Style="{StaticResource DateCalculation_CalendarPickerStyle}"
AutomationProperties.LabeledBy="{x:Bind Date_ToLabel}"
CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}"
Closed="CalendarFlyoutClosed"
DateChanged="ToDate_DateChanged"/>
<!-- Difference Result -->
@ -501,6 +502,7 @@
Style="{StaticResource DateCalculation_CalendarPickerStyle}"
AutomationProperties.LabeledBy="{x:Bind AddSubtract_Date_FromLabel}"
CalendarViewStyle="{StaticResource DateCalculation_CalendarViewStyle}"
Closed="CalendarFlyoutClosed"
DateChanged="AddSubtract_DateChanged"/>
<Grid Grid.Row="4">
@ -514,6 +516,7 @@
MinWidth="80"
MaxWidth="160"
VerticalAlignment="Top"
Checked="AddSubtractOption_Checked"
IsChecked="{Binding IsAddMode, Mode=TwoWay}"/>
<RadioButton x:Name="SubtractOption"
x:Uid="SubtractOption"
@ -522,6 +525,7 @@
MaxWidth="160"
Margin="20,0,0,0"
VerticalAlignment="Top"
Checked="AddSubtractOption_Checked"
IsChecked="{Binding IsAddMode, Converter={StaticResource BooleanNegationConverter}, Mode=TwoWay}"/>
</Grid>
@ -549,6 +553,7 @@
Grid.Row="1"
MinWidth="84"
AutomationProperties.LabeledBy="{Binding ElementName=YearsLabel}"
DropDownClosed="OffsetDropDownClosed"
ItemsSource="{Binding OffsetValues, Mode=OneTime}"
SelectedIndex="{Binding YearsOffset, Mode=TwoWay}"
SelectionChanged="OffsetValue_Changed"/>
@ -564,6 +569,7 @@
MinWidth="84"
Margin="12,0,12,0"
AutomationProperties.LabeledBy="{Binding ElementName=MonthsLabel}"
DropDownClosed="OffsetDropDownClosed"
ItemsSource="{Binding OffsetValues, Mode=OneTime}"
SelectedIndex="{Binding MonthsOffset, Mode=TwoWay}"
SelectionChanged="OffsetValue_Changed"/>
@ -578,6 +584,7 @@
Grid.Column="2"
MinWidth="84"
AutomationProperties.LabeledBy="{Binding ElementName=DaysLabel}"
DropDownClosed="OffsetDropDownClosed"
ItemsSource="{Binding OffsetValues, Mode=OneTime}"
SelectedIndex="{Binding DaysOffset, Mode=TwoWay}"
SelectionChanged="OffsetValue_Changed"/>

View file

@ -182,10 +182,6 @@ void DateCalculator::DateCalcOption_Changed(_In_ Platform::Object^ sender, _In_
{
FindName("AddSubtractDateGrid");
DateCalculationOption->SelectionChanged -= m_dateCalcOptionChangedEventToken;
DateResultLabel->RegisterPropertyChangedCallback(TextBlock::TextProperty, ref new DependencyPropertyChangedCallback(this, &DateCalculator::OnDateResultLabelChanged));
DateDiffAllUnitsResultLabel->RegisterPropertyChangedCallback(TextBlock::TextProperty, ref new DependencyPropertyChangedCallback(this, &DateCalculator::OnDateResultLabelChanged));
}
void CalculatorApp::DateCalculator::AddSubtractDateGrid_Loaded(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e)
@ -211,8 +207,25 @@ void DateCalculator::ReselectCalendarDate(_In_ Windows::UI::Xaml::Controls::Cale
calendarDatePicker->IsCalendarOpen = false;
}
void DateCalculator::OnDateResultLabelChanged(Windows::UI::Xaml::DependencyObject^ sender, Windows::UI::Xaml::DependencyProperty^ dp)
void DateCalculator::OffsetDropDownClosed(_In_ Object^ sender, _In_ Object^ e)
{
String^ automationName = AutomationProperties::GetName(sender);
TextBlockAutomationPeer::FromElement((TextBlock^)sender)->RaiseAutomationEvent(AutomationEvents::LiveRegionChanged);
RaiseLiveRegionChangedAutomationEvent(false);
}
void DateCalculator::CalendarFlyoutClosed(_In_ Object^ sender, _In_ Object^ e)
{
auto dateCalcViewModel = safe_cast<DateCalculatorViewModel^>(this->DataContext);
RaiseLiveRegionChangedAutomationEvent(dateCalcViewModel->IsDateDiffMode);
}
void DateCalculator::RaiseLiveRegionChangedAutomationEvent(_In_ bool isDateDiffMode)
{
TextBlock^ resultTextBlock = (isDateDiffMode ? DateDiffAllUnitsResultLabel : DateResultLabel);
String^ automationName = AutomationProperties::GetName(resultTextBlock);
TextBlockAutomationPeer::FromElement(resultTextBlock)->RaiseAutomationEvent(AutomationEvents::LiveRegionChanged);
}
void CalculatorApp::DateCalculator::AddSubtractOption_Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
RaiseLiveRegionChangedAutomationEvent(false);
}

View file

@ -38,9 +38,13 @@ namespace CalculatorApp
void OnLoaded(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void DateCalcOption_Changed(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
void AddSubtractDateGrid_Loaded(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs^ e);
void AddSubtractOption_Checked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
void ReselectCalendarDate(_In_ Windows::UI::Xaml::Controls::CalendarDatePicker^ calendarDatePicker, Windows::Foundation::DateTime dateTime);
void OnDateResultLabelChanged(Windows::UI::Xaml::DependencyObject ^ sender, Windows::UI::Xaml::DependencyProperty ^ dp);
void OffsetDropDownClosed(_In_ Platform::Object^ sender, _In_ Platform::Object^ e);
void CalendarFlyoutClosed(_In_ Platform::Object^ sender, _In_ Platform::Object^ e);
void RaiseLiveRegionChangedAutomationEvent(_In_ bool isDateDiffMode);
Windows::Foundation::EventRegistrationToken m_dateCalcOptionChangedEventToken;
void AddOption_Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}