XAML Code Inspection

I have a requirement where I want to validate that the XAML should contain an Automation ID attribute for all the UI Controls (Button,ComboBox,TextBox...etc), if the Automation ID attribute misses in XAML the build or resharper should throw an error.


Below is the XAML file:- 

<Button Name="Button" Content="Button" HorizontalAlignment="Left" Margin="505,177,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<Label Name="Label1" Content="Control Trigger" HorizontalAlignment="Left" Margin="285,380,0,0" VerticalAlignment="Top" Width="91" Height="28"/>
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="25" Margin="381,413,0,0" VerticalAlignment="Top" Width="211"/>
<CheckBox Name="ChkBox1" Content="CheckBox" HorizontalAlignment="Left" Margin="303,351,0,0" VerticalAlignment="Top"/>
<ComboBox Name="cboBox" IsEditable="True" HorizontalAlignment="Left" Margin="185,177,0,0" VerticalAlignment="Top" Width="92" Height="20">


The above XAML file does not contains AutomationID attribute for the UI Controls.


How can i add a code rule to inspect the missing attribute in XAML file?

Comment actions Permalink



here's the list of ReSharper XAML inspections - https://www.jetbrains.com/help/resharper/Reference__Code_Inspections_XAML.html.

You could try adding a search pattern using "Structural Search and Replace" feature - https://www.jetbrains.com/help/resharper/Code_Inspection__Creating_Custom_Inspections_and_QuickFixes.html.

Thank you.

Comment actions Permalink


I followed the steps for Creating custom inspections however when i tried to use "Structural Search and replace" in XAML file there was no pre-parsed code generated in Search and pattern dialog, thus i was not able to create a custom inspection.


If possible could you please share the steps for custom inspection for XAML file as the above link works for C# code and does not explains for XAML.







Please sign in to leave a comment.