Static XAML Definition
To specify a unique automation property for a control that is defined in your XAML file, you can set the AutomationProperties.AutomationId or AutomationProperties.Name implicitly or explicitly, as shown in the following examples. Setting either of these values gives the control a unique automation property that can be used to identify the control when you create a coded UI test or action recording.
Set the Property Implicitly
Set the AutomationProperties.AutomationId to ButtonX using the Name property in the XAML for the control.
<Button Name="ButtonX" Height="31" HorizontalAlignment="Left" Margin="23,26,0,0" VerticalAlignment="Top" Width="140" Click="ButtonX_Click" />
Set the Property Explicitly
Set the AutomationProperties.AutomationId to ButtonX explicitly in the XAML for the control.
<Button AutomationProperties.AutomationId=“ButtonX” Height="31" HorizontalAlignment="Left" Margin="23,26,0,0" VerticalAlignment="Top" Width="140" Click="ButtonX_Click" />
Read more: Vishnu's Blog