Skip to content

Commit 9b441a3

Browse files
authored
Merge pull request #317 from microsoft/DataBindingDemo-AccessibilityFixes
Data binding demo accessibility fixes
2 parents e23a284 + 62ac489 commit 9b441a3

File tree

6 files changed

+55
-11
lines changed

6 files changed

+55
-11
lines changed

Sample Applications/DataBindingDemo/AddProductWindow.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
using System;
55
using System.Windows;
6+
using System.Windows.Automation;
7+
using System.Windows.Automation.Peers;
8+
using System.Windows.Controls;
69

710
namespace DataBindingDemo
811
{
@@ -29,5 +32,20 @@ private void SubmitProduct(object sender, RoutedEventArgs e)
2932
((App) Application.Current).AuctionItems.Add(item);
3033
Close();
3134
}
35+
36+
private void OnValidationError(object sender, ValidationErrorEventArgs e)
37+
{
38+
// Get the current UIA ItemStatus from the element element.
39+
var oldStatus = AutomationProperties.GetItemStatus((DependencyObject)sender);
40+
41+
// Set some sample new ItemStatus here...
42+
var newStatus = e.Action == ValidationErrorEventAction.Added ? e.Error.ErrorContent.ToString() : String.Empty;
43+
AutomationProperties.SetItemStatus((DependencyObject)sender, newStatus);
44+
45+
// Having just set the new ItemStatus, raise a UIA property changed event. Note that the peer may
46+
// be null here unless a UIA client app such as Narrator or the AccEvent SDK tool are running.
47+
var automationPeer = UIElementAutomationPeer.FromElement((UIElement)sender);
48+
automationPeer?.RaisePropertyChangedEvent(AutomationElementIdentifiers.ItemStatusProperty, oldStatus, newStatus);
49+
}
3250
}
33-
}
51+
}

Sample Applications/DataBindingDemo/AddProductWindow.xaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@
5757
<TextBlock Grid.Row="2" Grid.Column="0" Style="{StaticResource SmallTitleStyle}" Margin="0,5,0,5">Start Price:</TextBlock>
5858

5959
<TextBox Name="StartPriceEntryForm" AutomationProperties.Name="Start Price" Grid.Row="2" Grid.Column="1"
60-
Style="{StaticResource TextStyleTextBox}" Margin="8,5,0,5">
60+
Style="{StaticResource TextStyleTextBox}" Margin="8,5,0,5"
61+
Validation.Error="OnValidationError">
6162
<TextBox.Text>
62-
<Binding Path="StartPrice" UpdateSourceTrigger="PropertyChanged">
63+
<Binding Path="StartPrice" UpdateSourceTrigger="PropertyChanged"
64+
NotifyOnValidationError="True">
6365
<Binding.ValidationRules>
6466
<ExceptionValidationRule />
6567
</Binding.ValidationRules>
@@ -71,9 +73,12 @@
7173

7274
<TextBox Name="StartDateEntryForm" AutomationProperties.Name="Start Date" Grid.Row="3" Grid.Column="1"
7375
Validation.ErrorTemplate="{StaticResource ValidationTemplate}"
74-
Style="{StaticResource TextStyleTextBox}" Margin="8,5,0,5">
76+
Style="{StaticResource TextStyleTextBox}" Margin="8,5,0,5"
77+
Validation.Error="OnValidationError"
78+
AutomationProperties.LiveSetting="Assertive">
7579
<TextBox.Text>
7680
<Binding Path="StartDate" UpdateSourceTrigger="PropertyChanged"
81+
NotifyOnValidationError="True"
7782
Converter="{StaticResource DateConverter}">
7883
<Binding.ValidationRules>
7984
<local:FutureDateRule />

Sample Applications/DataBindingDemo/AuctionItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public int StartPrice
103103
{
104104
if (value < 0)
105105
{
106-
throw new ArgumentException("Price must be positive");
106+
throw new ArgumentException("Price must be positive. Provide a positive price");
107107
}
108108
_startPrice = value;
109109
OnPropertyChanged("StartPrice");

Sample Applications/DataBindingDemo/FutureDateRule.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
1818
}
1919
catch (FormatException)
2020
{
21-
return new ValidationResult(false, "Value is not a valid date.");
21+
return new ValidationResult(false, "Value is not a valid date. Please enter a valid date");
2222
}
2323
if (DateTime.Now.Date > date)
2424
{
25-
return new ValidationResult(false, "Please enter a date in the future.");
25+
return new ValidationResult(false, "Value is not a future date. Please enter a date in the future.");
2626
}
2727
return ValidationResult.ValidResult;
2828
}
29+
2930
}
30-
}
31+
}

Sample Applications/DataBindingDemo/MainWindow.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// // Copyright (c) Microsoft. All rights reserved.
22
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.Collections.Specialized;
45
using System.ComponentModel;
56
using System.Windows;
7+
using System.Windows.Automation;
8+
using System.Windows.Automation.Peers;
69
using System.Windows.Data;
710

811
namespace DataBindingDemo
@@ -41,11 +44,21 @@ private void AddGrouping(object sender, RoutedEventArgs args)
4144
// This groups the items in the view by the property "Category"
4245
var groupDescription = new PropertyGroupDescription {PropertyName = "Category"};
4346
_listingDataView.GroupDescriptions.Add(groupDescription);
47+
48+
NotifyUpdate();
49+
50+
}
51+
52+
private void NotifyUpdate()
53+
{
54+
var listingPeer = ListBoxAutomationPeer.FromElement(Master);
55+
listingPeer.RaiseAutomationEvent(AutomationEvents.LiveRegionChanged);
4456
}
4557

4658
private void RemoveGrouping(object sender, RoutedEventArgs args)
4759
{
4860
_listingDataView.GroupDescriptions.Clear();
61+
NotifyUpdate();
4962
}
5063

5164
private void AddSorting(object sender, RoutedEventArgs args)
@@ -57,21 +70,26 @@ private void AddSorting(object sender, RoutedEventArgs args)
5770
new SortDescription("Category", ListSortDirection.Ascending));
5871
_listingDataView.SortDescriptions.Add(
5972
new SortDescription("StartDate", ListSortDirection.Ascending));
73+
NotifyUpdate();
6074
}
6175

6276
private void RemoveSorting(object sender, RoutedEventArgs args)
6377
{
6478
_listingDataView.SortDescriptions.Clear();
79+
NotifyUpdate();
6580
}
6681

6782
private void AddFiltering(object sender, RoutedEventArgs args)
6883
{
6984
_listingDataView.Filter += ShowOnlyBargainsFilter;
85+
NotifyUpdate();
7086
}
7187

7288
private void RemoveFiltering(object sender, RoutedEventArgs args)
7389
{
7490
_listingDataView.Filter -= ShowOnlyBargainsFilter;
91+
NotifyUpdate();
7592
}
7693
}
77-
}
94+
95+
}

Sample Applications/DataBindingDemo/MainWindow.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@
5252
</CheckBox>
5353

5454

55-
<ListBox Name="Master" AutomationProperties.Name="Master" Grid.Row="2" Grid.ColumnSpan="3" Margin="8"
56-
ItemsSource="{Binding Source={StaticResource ListingDataView}}">
55+
<ListBox Name="Master" AutomationProperties.Name="List of Items For Sale" Grid.Row="2" Grid.ColumnSpan="3" Margin="8"
56+
ItemsSource="{Binding Source={StaticResource ListingDataView}}"
57+
AutomationProperties.LiveSetting="Assertive">
5758
<ListBox.GroupStyle>
5859
<GroupStyle
5960
HeaderTemplate="{StaticResource GroupingHeaderTemplate}" />
@@ -68,5 +69,6 @@
6869
<Button Name="OpenAddProduct" Grid.Row="4" Grid.Column="1" Content="Add Product" HorizontalAlignment="Center"
6970
Margin="8"
7071
Click="OpenAddProductWindow" />
72+
7173
</Grid>
7274
</Window>

0 commit comments

Comments
 (0)