Can't get tab title from WPF TabControl when using custom TabItem template
See original GitHub issueIn my WPF application, I’m using a TabControl
with a custom style for the TabItem
s (the buttons you click to switch tabs). When I use this custom style, I’m unable to access the TextBox
element to test what text the TabItem
is displaying.
For example, here is the XAML code for my TabControl:
<TabControl TabStripPlacement="Left" Background="{x:Null}" ItemsSource="{Binding Tabs}" SelectedIndex="0">
<TabControl.Resources>
<Style TargetType="TabItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock Text="{Binding Key}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
<TabControl.ContentTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Value}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
When I run my app and use the Inspect tool, I can view the TextBlock
inside the TabItem
. But when I try to get this element through the Appium test framework, it doesn’t exist.
I thought anything visible through Inspect should be available to test, so I guess this is a bug. I have a test project to demonstrate, if you want to see it let me know how/where to upload it.
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
How to get the header of the selected item in a TabControl ...
I put the text I needed in the Tag of the TabItem, and displayed that in my template.
Read more >Using the WPF TabControl
A detailed walkthrough of the WPF TabControl - how to use and customize it. ... by clicking on the tab header, usually positioned...
Read more >WPF TabControl: Styling the TabItems
Learn how to style the TabItem elements of the WPF TabControl with this complete walkthrough.
Read more >DataBinding in WPF TabControl (TabControlExt)
The TabControl can bound to an external source to auto create tabs and display the data using ItemsSource property. When you are auto...
Read more >TabControl Class (System.Windows.Controls)
Gets or sets a DataTemplateSelector that provides custom logic for choosing the template that is used to display the content of the control....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@craigbrown this is blocking us as well. Really wanted this architecture (WinAppDriver - Selenium in xUnit tests) to work but I can’t get past this issue. Exact same problems for me. I’ve tried two different versions of WinAppDriver but it just won’t see anything inside my derived button control, which gets its content from a style which sets the ContentTemplate (with textblocks and stuff that I can’t see). Everything is seen in inspect just fine. I’ve tried reloading the driver (switching back to the running window in a new session), I’ve tried reloading the button, I’ve tried hovering the mouse over the button before reloading it (FindElement). I also wrote a customer AutomationPeer to make sure the children are added to the list returned by GetChildrenCore (they are and the GetChildrenCore is being called) but the return from the GetElements on the custom button just returns the single Element for the custom button, none of those children.
I’m attaching a sample wpf project that has a single button with a style. You can see the textblock that says ON or OFF in inspect, but can’t see it within the button elements in WinAppDriver. This is slightly different than your issues but I’m guessing they are related. I attached this project in another issue specifically about buttons as well winappdriverbug.zip .