Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 重写CodedUI测试的DataGridRow样式会产生不需要的外观_Wpf_Xaml_Datagrid_Styles_Coded Ui Tests - Fatal编程技术网

Wpf 重写CodedUI测试的DataGridRow样式会产生不需要的外观

Wpf 重写CodedUI测试的DataGridRow样式会产生不需要的外观,wpf,xaml,datagrid,styles,coded-ui-tests,Wpf,Xaml,Datagrid,Styles,Coded Ui Tests,由于CodedUI的一些缺点,很难在DataGrid中选择项。我发现的一个解决方法是覆盖ItemContainerStyle,如下所示: <DataGrid.ItemContainerStyle> <Style TargetType="{x:Type DataGridRow}"> <Setter Property="AutomationProperties.AutomationId"> <Setter.V

由于CodedUI的一些缺点,很难在DataGrid中选择项。我发现的一个解决方法是覆盖ItemContainerStyle,如下所示:

<DataGrid.ItemContainerStyle>
     <Style TargetType="{x:Type DataGridRow}">

        <Setter Property="AutomationProperties.AutomationId">
           <Setter.Value>
              <MultiBinding StringFormat="ArisingID_{0}">
                <Binding Path="(DataGridRow.Tag)" RelativeSource="{RelativeSource Mode=Self}" />
              </MultiBinding>
           </Setter.Value>
        </Setter>

        <Setter Property="AutomationProperties.Name">
           <Setter.Value>
              <MultiBinding StringFormat="ArisingID_{0}">
                 <Binding Path="(DataGridRow.Tag)" RelativeSource="{RelativeSource Mode=Self}" />
              </MultiBinding>
           </Setter.Value>
        </Setter>

     </Style>
</DataGrid.ItemContainerStyle>
然而,一个问题是,这会覆盖数据网格行的某些“默认样式”——数据网格上的每个单元格似乎都是单独可选择的,而不是作为一行


将默认样式与这些修改结合在一起的最佳方式是什么?

有一个
BasedOn
将设置您的样式,然后添加您添加的额外设置器:

<DataGrid.ItemContainerStyle>
    <Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource DataGridRowStyle}">

    <Setter Property="AutomationProperties.AutomationId">
       <Setter.Value>
          <MultiBinding StringFormat="ArisingID_{0}">
            <Binding Path="(DataGridRow.Tag)" RelativeSource="{RelativeSource Mode=Self}" />
          </MultiBinding>
       </Setter.Value>
    </Setter>

    <Setter Property="AutomationProperties.Name">
       <Setter.Value>
          <MultiBinding StringFormat="ArisingID_{0}">
             <Binding Path="(DataGridRow.Tag)" RelativeSource="{RelativeSource Mode=Self}" />
          </MultiBinding>
       </Setter.Value>
    </Setter>

 </Style>


我肯定需要在某个地方定义“DataGridRowStyle”吗?我真的不明白这是从哪里来的?我假设你有一种风格,但当你在你的例子中添加这些二传手时,就失去了它。但你真的失去了默认行为?我失去了默认行为,是的。我确实定义了一个默认样式,但它没有x:Key(因此所有其他DataGridRows都默认为该样式)。如果我添加x:Key和BasedOn,它对我当前的DataGrid有效,但其他所有的都不行!
<DataGrid.ItemContainerStyle>
    <Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource DataGridRowStyle}">

    <Setter Property="AutomationProperties.AutomationId">
       <Setter.Value>
          <MultiBinding StringFormat="ArisingID_{0}">
            <Binding Path="(DataGridRow.Tag)" RelativeSource="{RelativeSource Mode=Self}" />
          </MultiBinding>
       </Setter.Value>
    </Setter>

    <Setter Property="AutomationProperties.Name">
       <Setter.Value>
          <MultiBinding StringFormat="ArisingID_{0}">
             <Binding Path="(DataGridRow.Tag)" RelativeSource="{RelativeSource Mode=Self}" />
          </MultiBinding>
       </Setter.Value>
    </Setter>

 </Style>