DataGrid项的.Net AutomationProperties名称不会更改

时间:2018-04-09 20:35:36

标签: c# .net wpf xaml automation

我尝试更改DataGrid内的AutomationPropertiesDataGrid名称项,但它永远不会更改,通常会将类名称设为AutomationProperties名称。

XAML中的代码

<DataGrid>             <!-- added by edit -->
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Path=Name}" ElementStyle="{StaticResource DataGridTextCellStyle}" Header="Name" Width="Auto"/>
        <DataGridTextColumn Binding="{Binding Path=Value}" ElementStyle="{StaticResource DataGridTextCellStyle}" Header="Value" Width="Auto">
            <DataGridTextColumn.CellStyle>
                <Style TargetType="DataGridCell" BasedOn="{StaticResource dgcStyle}">
                    <Setter Property="ToolTip" Value="{Binding Path=Value, TargetNullValue='No value'}"/>
                    <Setter Property="AutomationProperties.Name" Value="{Binding Path=Value, TargetNullValue='No value'}"/>
                </Style>
            </DataGridTextColumn.CellStyle>
        </DataGridTextColumn>
    </DataGrid.Columns>
    <DataGrid.ItemContainerStyle>
        <Style TargetType="{x:Type DataGridRow}">
            <Setter Property="AutomationProperties.Name" Value="{Binding Path=AutomationName}"/>
            <Setter Property="Focusable" Value="True"/>
            <Setter Property="IsTabStop" Value="False"/>
        </Style>
    </DataGrid.ItemContainerStyle>
</DataGrid>

正如您所见,即使我使用datagrid.itemcontainerstyle,但名称仍然类似于路径&#34; App.Shared.Models.ItemModel&#34;