title: AutomationProperties.AutomationId on custom control not exposed
body: <p>I've been banging my head against this problem for 3 days and haven't been able to find an answer.</p>
  
  <p>I've got an application written in WPF (dot Net 4.5) and I'm working with Teststack.White trying to write some automated GUI test cases. The developers have given x:Names to some of the controls and they show up through Inspect/WPF Inspector/Visual UI Automation Verify as the AutomationId just fine.</p>
  
  <p>There are other controls that are buried a bit deeper that I've been tasked with giving automation ids to (mostly as an exercise so I can get more familiar with the back-end). This is where I've been banging my head against things.</p>
  
  <p>I've tried giving the controls the AutomationProperties.AutomationId (and .Name) attribute. I've given AutomationProperties a name space definition. As well I've made sure SWA.Peers is referenced.</p>
  
  <p>I haven't tried using property setters in XAML as they don't make much sense currently and I'm hoping don't need to write stuff in C# to set them (if I do, I'll do it but just hoping).</p>
  
  <p>One of my co-workers sat down and we pulled out the bare minimum setup that isn't exposing the Automation ID property (unfortunately he as well as the other devs are drawing a blank as to why this isn't happening). It looks like:</p>
  
  <p>MainWindow.xaml:</p>
  
  <pre><code>&lt;Window x:Class="TestAutomationUI.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:autoProp="clr-namespace:System.Windows.Automation;assembly=PresentationCore"
      xmlns:common="clr-namespace:Asi.Ui.Common"
      Title="Test UI (Pick me)" Height="455.075" Width="525"&gt;
  
      &lt;Window.Resources&gt;
          &lt;ResourceDictionary&gt;
          &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;ResourceDictionary Source="/IconLabelButton.xaml" /&gt;
          &lt;/ResourceDictionary.MergedDictionaries&gt;
          &lt;/ResourceDictionary&gt;
      &lt;/Window.Resources&gt;
  
      &lt;StackPanel x:Name="PresentationRoot"&gt;
          &lt;common:IconLabelButton x:Name="TestButton" autoProp:AutomationProperties.AutomationId="TestButtonClick" Text="Stuff" Margin="245,0,214.4,0" RenderTransformOrigin="4.648,0.588" Height="32"&gt;
          &lt;/common:IconLabelButton&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>IconLabelButton.xaml:</p>
  
  <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:autoProp="clr-namespace:System.Windows.Automation;assembly=PresentationCore"
                      xmlns:common="clr-namespace:Asi.Ui.Common"&gt;
  
      &lt;Style TargetType="common:IconLabelButton"&gt;
          &lt;Setter Property="Template" Value="{DynamicResource Asi.Ui.Common.IconLabelButton}" /&gt;
          &lt;Setter Property="IsTabStop" Value="False" /&gt;
          &lt;Setter Property="Background" Value="Transparent" /&gt;
          &lt;Setter Property="FontWeight" Value="{DynamicResource Mobius.UI.Resources.Fonts.WeightLight}"/&gt;
          &lt;Setter Property="Spacing" Value="10" /&gt;
      &lt;/Style&gt;
  
      &lt;ControlTemplate x:Key="Asi.Ui.Common.IconLabelButton" TargetType="common:IconLabelButton"&gt;
          &lt;Border Background="{TemplateBinding Background}" Height="30"&gt;
              &lt;Button Style="{DynamicResource Mobius.UI.Resources.Styles.IconButton}" Margin="0" Padding="0" HorizontalContentAlignment="Stretch" HorizontalAlignment="Left"
                      Command="{TemplateBinding Command}" CommandParameter="{TemplateBinding CommandParameter}" Foreground="{TemplateBinding Foreground}"&gt;
  
                  &lt;Grid&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="22" /&gt;
                          &lt;ColumnDefinition Width="{TemplateBinding Spacing}" /&gt;
                          &lt;ColumnDefinition Width="*" /&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;Grid Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="22" Height="22"&gt;
                          &lt;Path Margin="1" Height="20" Width="20" Fill="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ContentControl}}}" Data="{TemplateBinding Icon}" Stretch="Fill"/&gt;
                          &lt;Path Margin="1" Height="20" Width="20" Fill="{TemplateBinding AdornerIconFill}" Data="{TemplateBinding AdornerIcon}" Stretch="Fill"/&gt;
                      &lt;/Grid&gt;
                      &lt;TextBlock Grid.Column="2" Text="{TemplateBinding Text}" VerticalAlignment="Center" Foreground="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type ContentControl}}}" FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}" FontStretch="{TemplateBinding FontStretch}" FontWeight="{TemplateBinding FontWeight}"/&gt;
                  &lt;/Grid&gt;
              &lt;/Button&gt;
          &lt;/Border&gt;
      &lt;/ControlTemplate&gt;
  
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>IconLabelButton.xaml.cs:</p>
  
  <pre><code>    using System;
  using System.Windows;
  using System.Windows.Automation;
  using System.Windows.Automation.Peers;
  using System.Windows.Controls;
  using System.Windows.Input;
  using System.Windows.Media;
  
  namespace Asi.Ui.Common
  {
  
      public class IconLabelButton : Control
      {
  
          public static readonly DependencyProperty TextProperty =
              DependencyProperty.Register("Text", typeof(string), typeof(IconLabelButton), new PropertyMetadata(default(string)));
  
          public static readonly DependencyProperty AdornerIconProperty =
              DependencyProperty.Register("AdornerIcon", typeof(object), typeof(IconLabelButton), new PropertyMetadata(default(object)));
  
          public static readonly DependencyProperty IconProperty =
              DependencyProperty.Register("Icon", typeof(object), typeof(IconLabelButton), new PropertyMetadata(default(object)));
  
          public static readonly DependencyProperty CommandProperty =
              DependencyProperty.Register("Command", typeof(ICommand), typeof(IconLabelButton), new PropertyMetadata(default(ICommand)));
  
          public static readonly DependencyProperty CommandParameterProperty =
              DependencyProperty.Register("CommandParameter", typeof(object), typeof(IconLabelButton), new PropertyMetadata(default(ICommand)));
  
          public static readonly DependencyProperty SpacingProperty =
              DependencyProperty.Register("Spacing", typeof(GridLength), typeof(IconLabelButton), new PropertyMetadata(default(GridLength)));
  
          public static readonly DependencyProperty IconButtonSizeProperty =
              DependencyProperty.Register("IconButtonSize", typeof(GridLength), typeof(IconLabelButton), new PropertyMetadata(default(GridLength)));
  
          public static readonly DependencyProperty AdornerIconFillProperty =
              DependencyProperty.Register("AdornerIconFill", typeof(Brush), typeof(IconLabelButton), new PropertyMetadata(default(Brush)));
  
  
          static IconLabelButton()
          {
              DefaultStyleKeyProperty.OverrideMetadata(typeof(IconLabelButton), new FrameworkPropertyMetadata(typeof(IconLabelButton)));
          }
  
          public string Text
          {
              get { return (string)GetValue(TextProperty); }
              set { SetValue(TextProperty, value); }
          }
          public object AdornerIcon
          {
              get { return GetValue(AdornerIconProperty); }
              set { SetValue(AdornerIconProperty, value); }
          }
          public object Icon
          {
              get { return GetValue(IconProperty); }
              set { SetValue(IconProperty, value); }
          }
          public ICommand Command
          {
              get { return (ICommand)GetValue(CommandProperty); }
              set { SetValue(CommandProperty, value); }
          }
          public object CommandParameter
          {
              get { return GetValue(CommandParameterProperty); }
              set { SetValue(CommandParameterProperty, value); }
          }
          public GridLength Spacing
          {
              get { return (GridLength)GetValue(SpacingProperty); }
              set { SetValue(SpacingProperty, value); }
          }
          public GridLength IconButtonSize
          {
              get { return (GridLength)GetValue(IconButtonSizeProperty); }
              set { SetValue(IconButtonSizeProperty, value); }
          }
          public Brush AdornerIconFill
          {
              get { return (Brush)GetValue(AdornerIconFillProperty); }
              set { SetValue(AdornerIconFillProperty, value); }
          }
      }
  }
  </code></pre>
  
  <p>I apologize if this is an easy question (or if I'm not asking the right one). I'm an entry-level programmer who only has a cursory familiarity with WPF/XAML.</p>
  
  <p>Thanks in advance for the help! (Hopefully it's any easy fix!)</p>
  
  <p><strong>Update:</strong> After doing some further digging on UI Automation Providers, it looks like all custom controls have to be written to support AutomationProperties. Of course talking with the devs that isn't case.</p>
  
  <p>I'll post more information when I get the solution figured out.</p>