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

View file

@ -182,10 +182,6 @@ void DateCalculator::DateCalcOption_Changed(_In_ Platform::Object^ sender, _In_
{ {
FindName("AddSubtractDateGrid"); FindName("AddSubtractDateGrid");
DateCalculationOption->SelectionChanged -= m_dateCalcOptionChangedEventToken; 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) 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; 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); RaiseLiveRegionChangedAutomationEvent(false);
TextBlockAutomationPeer::FromElement((TextBlock^)sender)->RaiseAutomationEvent(AutomationEvents::LiveRegionChanged); }
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 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 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 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 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; Windows::Foundation::EventRegistrationToken m_dateCalcOptionChangedEventToken;
void AddOption_Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
}; };
} }