none
TabControl controls are missing for UI Automation RRS feed

  • Question

  • I am attempting to automate a WPF web application using the UI Automation classes from a seperate C# application. The WPF "server" application, however, has much of its content (controls) on a TabControl, which has a style applied to it:

    From Main.xaml:
    <
    TabControl x:Name="tcRoot" Style="{StaticResource EmptyTabControlStyle}" Grid.Row="1">

    From TabControl.xaml:
    <ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Style x:Key="EmptyTabControlStyle" TargetType="{x:Type TabControl}">
            <Setter Property="OverridesDefaultStyle" Value="True" />
            <Setter Property="SnapsToDevicePixels" Value="True" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabControl}">
                        <ContentPresenter ContentSource="SelectedContent" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </
    ResourceDictionary>

    I have found that as soon as you apply a style to the TabControl, all of its contained controls disappear. They are no longer found with UI Automation, and the UI Spy tool cannot find them either.


    Is there something wrong with the way the styling is done that is causing this?
    Is this simply a bug?
    Is there a workaround?


    TrevorWP
    • Edited by TPaesl Monday, July 28, 2008 4:25 PM Fix code
    Friday, July 25, 2008 9:51 PM

Answers

  • The TabControl class defines a template part called PART_SelectedContentHost, of type ContentPresenter. You should ensure that your template matches this. It's quite possible that the control uses this template part for its UI automation server.
    Controls for WPF and Windows Forms at http://www.divelements.co.uk
    • Marked as answer by TPaesl Monday, July 28, 2008 4:28 PM
    • Marked as answer by TPaesl Monday, July 28, 2008 4:28 PM
    • Marked as answer by TPaesl Monday, July 28, 2008 4:28 PM
    Saturday, July 26, 2008 8:34 AM

All replies

  • The TabControl class defines a template part called PART_SelectedContentHost, of type ContentPresenter. You should ensure that your template matches this. It's quite possible that the control uses this template part for its UI automation server.
    Controls for WPF and Windows Forms at http://www.divelements.co.uk
    • Marked as answer by TPaesl Monday, July 28, 2008 4:28 PM
    • Marked as answer by TPaesl Monday, July 28, 2008 4:28 PM
    • Marked as answer by TPaesl Monday, July 28, 2008 4:28 PM
    Saturday, July 26, 2008 8:34 AM
  • Tim,

    You were absolutely correct--thanks. This solved all my problems! The simple code change is highlighted in green:

    <ResourceDictionary
    xmlns
    ="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

        <Style x:Key="EmptyTabControlStyle" TargetType="{x:Type TabControl}">
            <Setter Property="OverridesDefaultStyle" Value
    ="True" />
            <Setter Property="SnapsToDevicePixels" Value
    ="True" />
            <Setter Property
    ="Template">
                <Setter.Value
    >
                    <ControlTemplate TargetType="{x:Type TabControl
    }">
                        <ContentPresenter Name="PART_SelectedContentHost" ContentSource
    ="SelectedContent" />
                    </ControlTemplate
    >
                </Setter.Value
    >
            </Setter
    >
        </Style
    >
    </
    ResourceDictionary>

    TrevorWP
    Monday, July 28, 2008 4:28 PM
  • Hi All,

    I have a similar problem... but I'm using windows forms..
    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0203f174-e2ce-44f7-a240-8f2ed4bac877

    somebody can help me ?
    thanks in advance.
    Sunday, November 1, 2009 5:07 AM
  • Thanks!! This just provided a very simple fix to a big problem.

    Tuesday, June 1, 2010 9:59 PM
  • I know this is an old thread, but I am having the same issue even with the Name of the content presenter set correctly. It seems to happen with .NET 4.5 and .NET 4.0 but not with 3.5. I have a very simple WPF application showing the problem. Can anyone see the issue or propose a solution?

        <Grid>
            <StackPanel>
                <ComboBox Name="SelectedPage">
                    <System:Int32>0</System:Int32>
                    <System:Int32>1</System:Int32>
                </ComboBox>
    
                <TabControl x:Name="UnseenTabControl" SelectedIndex="{Binding ElementName=SelectedPage, Path=SelectedItem}" OverridesDefaultStyle="True">
                    <TabControl.Template>
                        <ControlTemplate TargetType="{x:Type TabControl}">
                            <Grid>
                                <ContentPresenter Name="PART_SelectedContentHost" Content="{TemplateBinding SelectedContent}"/>
                            </Grid>
                        </ControlTemplate>
                    </TabControl.Template>
                    <TabItem>
                        <Grid>
                            <Button Name="OnPage3">OnPage1</Button>
                        </Grid>
                    </TabItem>
    
                    <TabItem>
                        <Grid>
                            <Button Name="OnPage4" Margin="20" AutomationProperties.AutomationId="ButtonUAID">OnPage2</Button>
                            <Expander>
                                <Button Name="InsideExpander2">InsideExpander2</Button>
                            </Expander>
                        </Grid>
                    </TabItem>
                </TabControl>
            </StackPanel>
        </Grid>

    Thanks.

    Tuesday, November 6, 2012 11:51 AM
  • i'm facing the same issue, somebody, anybody, any ideas how to workaround this?

    -- FOUND SOLUTION HERE: --

    http://www.colinsalmcorner.com/2011/11/genericautomationpeer-helping-coded-ui.html

    • Edited by milrom Wednesday, November 27, 2013 12:49 PM
    Tuesday, November 26, 2013 4:04 PM