Summary
In my WPF application, I needed a TabControl with buttons on the left, so I defined a ControlTemplate with the layout I wanted and it worked fine.
However, my tester's automated testing tool can't see any of the content of the tabs, including the currently selected tab.
Question: How can I keep my TabControl testable by the automated testing tools, while still defining the ControlTemplate?
Details
I'm developing a WPF application using WPF 3.5
My tester is using an automated test tool called QTP
He says he can test anything you can see with UISpy.exe
Sample WPF application (Xaml):
<Window x:Class="TabControlTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Tab Control Test"
Height="300"
Width="300">
<Window.Resources>
<ControlTemplate x:Key="ButtonsOnLeftTabLayout"
TargetType="{x:Type TabControl}">
<DockPanel>
<StackPanel DockPanel.Dock="Left"
IsItemsHost="True" />
<ContentPresenter Content="{TemplateBinding SelectedContent}" />
</DockPanel>
</ControlTemplate>
</Window.Resources>
<TabControl Template="{StaticResource ButtonsOnLeftTabLayout}">
<TabItem Header="Tab 1">
<StackPanel>
<Button HorizontalAlignment="Center">Button 1</Button>
</StackPanel>
</TabItem>
<TabItem Header="Tab 2">
<StackPanel>
<Button HorizontalAlignment="Center">Button 2</Button>
</StackPanel>
</TabItem>
</TabControl>
</Window>
What my search has found so far:
(After search I finally found answer but it took longer than I thought it should have, and the AutomationPeer early findings were indeed incorrect, so I'm writing this as a SO question and self-answer, in case it helps anyone else in future)
Found answer in a different MSFT response on a different but similar msdn forum question, TabControl controls are missing for UI Automation.
To get the UI Automation working for ContentTemplated TabControl, add Name="PART_SelectedContentHost" attribute to the ContentPresenter, like this
<ContentPresenter Name="PART_SelectedContentHost"
Content="{TemplateBinding SelectedContent}"/>
That's all it takes. UISpy can now see the content of the currently selected tab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With