Setting AutomationProperties.Name to all parts

Editors for WPF Forum

Posted 8 years ago by FinallyInSeattle
Version: 10.1.0523
Avatar
Could someone suggest a way to assign a value to the AutomationProperties.Name of each part in the DateTimeEditBox control? We're going through accessibility testing and this aspect is failing. Thanks in advance!

[Modified at 09/09/2010 01:31 PM]

Comments (4)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

Your options are:

1. Use implicit Styles for the various parts (i.e. DateTimeMonthPart) with a setter for AutomationProperties.Name
2. Override the metadata for the AutomationProperties.NameProperty for the various parts
3. Explicitly set the AutomationProperties.NameProperty for the parts when they are created. This would require that you create a derivation of the parts-editor and it's group, which is a bit more work.

We will go ahead and set this by default for the next build. If you have any suggestions for the automation names, please let us know.


Actipro Software Support

Posted 8 years ago by FinallyInSeattle
Avatar
I'm attempting to do #2, but UISpy is still showing a blank for the Name property. Here's the code - am I missing something?:

    static ActiproDateTimeEditBox()
    {
      AutomationProperties.NameProperty.OverrideMetadata(typeof(DateTimeMonthPart), new FrameworkPropertyMetadata("Month"));
      AutomationProperties.NameProperty.OverrideMetadata(typeof(DateTimeDayPart), new FrameworkPropertyMetadata("Day"));
      AutomationProperties.NameProperty.OverrideMetadata(typeof(DateTimeYearPart), new FrameworkPropertyMetadata("Year"));
      AutomationProperties.NameProperty.OverrideMetadata(typeof(DateTimeHourPart), new FrameworkPropertyMetadata("Hour"));
      AutomationProperties.NameProperty.OverrideMetadata(typeof(DateTimeMinutePart), new FrameworkPropertyMetadata("Minute"));
    }
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

Sorry, the issue is that UI Spy lists the MaskedTextBox used in the control template of the various parts, not the part itself. You'd need to update the Style used on the MaskedTextBox to pull the automation name from the templated part. Something like this works:
<Style x:Key="{x:Static themes:EditorsCommonDictionary.MaskedTextBoxInlineStyleKey}"
        TargetType="editors:MaskedTextBox"
        BasedOn="{StaticResource {x:Static themes:EditorsCommonDictionary.MaskedTextBoxInlineStyleKey}}">
    <Setter Property="AutomationProperties.Name"
            Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(AutomationProperties.Name)}" />
</Style>
You can then set the automation name like you have, or use an implicit Style.


Actipro Software Support

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

Just fyi, we've updated the next maintenance release to set the Automation.Name property by default (like shown above).


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 7 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.