views:

50

answers:

1

Introduction

I have a ListView and want to format only the second column. The following XAML code does that:

<ListView x:Name="listview">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Property" DisplayMemberBinding="{Binding Path=Key}" Width="100"/>
            <!-- <GridViewColumn Header="Value" DisplayMemberBinding="{Binding Path=Value}" Width="250">-->
            <GridViewColumn Header="Value" Width="250">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=Value}" Foreground="CornflowerBlue" AutomationProperties.Name="{Binding Path=Key}"/>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

The one problem I have is that the AutomationProperties.Name property is not being set. I was checking it with the Coded UI Test Builder and the property is empty. The Text and the Foreground property are being set correctly.

Question

Does anyone know why AutomationProperties.Name is not being set?

Additional information

Strangly enough, the following XAML code does set the AutomationProperties.Name

<ListView x:Name="listview">
   <ListView.Resources>
       <Style TargetType="TextBlock">
           <Setter Property="AutomationProperties.Name" Value="{Binding Key}"/>
        </Style>
    </ListView.Resources>
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Property" DisplayMemberBinding="{Binding Path=Key}" Width="100"/>
            <GridViewColumn Header="Value" DisplayMemberBinding="{Binding Path=Value}" Width="250"/>
        </GridView>
    </ListView.View>
</ListView>

The problem here though is that AutomationProperties.Name is being set on all the columns. But I only want it on the second one because otherwise my Coded UI Test code returns the wrong value (that of the first column, instead of that of the second column which I want).

+2  A: 

Don't know if you're aware of this, but a very helpful tool in analyzing these types of problems is Snoop.

In particular, it will highlight (with red) any data binding errors you may have.

I took a look myself and it sure seems as if the first piece of xaml (above) is now working (after you cleared up the syntax error). In Snoop, bound properties are highlighted with a light green.

Here is a screen shot of Snoop showing the property is being set correctly: Snoop Screen Shot 1

And here is a screen shot of Snoop showing the TextBlock (where the property isn't set ... no light green column) on the first column: Snoop Screen Shot 2

And, finally, I've intentionally broken the binding to show you what Snoop shows when something is wrong and you have a data binding error (it is highlighted in red and one of the columns gives you additional information): Snoop Screen Shot 3

cplotts
+1, would upvote more if I could. Thank you very much for taking the time to try it out and for posting the awesome screenshots! You are right, Snoop is indeed showing that the property is set, however, Coded UI Test Builder is not. By the way, thanks a lot for Snoop 64bit.
Lernkurve
+1 for Snoop, I can't live without it...
Thomas Levesque
@Thomas Levesque, @Lernkurve: you guys are too kind! Thanks!
cplotts