question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't get tab title from WPF TabControl when using custom TabItem template

See original GitHub issue

In my WPF application, I’m using a TabControl with a custom style for the TabItems (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:open
  • Created 5 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
donbymathieucommented, Feb 11, 2022

@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.

0reactions
donbymathieucommented, Feb 21, 2022

@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 .

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found