白色 UI 自动化:获取 WPF DataGrid 单元格值?
我对白色项目非常陌生,我只是检查它的功能......在我的工作中,我集中处理 wpf 和 wpf 。数据网格, 当列是 DataGridTemplateColumn 时,我无法获取 datagrid 单元格的值。
它不仅仅适用于 DataGridTemplateColumn,它适用于所有列类型。
我的数据网格为:
<my:DataGrid AutoGenerateColumns="False" Margin="25,28,42,34" Name="dataGrid1" >
<my:DataGrid.Columns>
<my:DataGridTemplateColumn Header="Header" x:Name="koko" Width="200">
<my:DataGridTemplateColumn.CellTemplate >
<DataTemplate >
<TextBlock Name="moko" Text="{Binding col1, Mode=OneWay,Converter={StaticResource fataGridHighlightConverter }}" ></TextBlock>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
<my:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<Grid x:Name="myEditGrid" Loaded="myEditGrid_Loaded">
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellEditingTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
</my:DataGrid>
我的测试为:
[Test]
public void TestDatagrid5()
{
var tab = _win.Get<ListView>(SearchCriteria.ByAutomationId("dataGrid1"));
var count = tab.Rows.Count;
var row = tab.Rows[1];
ListViewCell x = row.Cells[1]; //Always count = 0 :(
}
但单元格计数始终 = 0,我需要获取单元格值!!!?请帮忙!
I'm very new to white project, and I wast just checking its features... In my work, I deal intensively with wpf & datagrids,
I couldn't get the value of datagrid cell when the column is DataGridTemplateColumn.
It's not for DataGridTemplateColumn only, It's is for all column types.
my datagrid was as:
<my:DataGrid AutoGenerateColumns="False" Margin="25,28,42,34" Name="dataGrid1" >
<my:DataGrid.Columns>
<my:DataGridTemplateColumn Header="Header" x:Name="koko" Width="200">
<my:DataGridTemplateColumn.CellTemplate >
<DataTemplate >
<TextBlock Name="moko" Text="{Binding col1, Mode=OneWay,Converter={StaticResource fataGridHighlightConverter }}" ></TextBlock>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
<my:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<Grid x:Name="myEditGrid" Loaded="myEditGrid_Loaded">
</Grid>
</DataTemplate>
</my:DataGridTemplateColumn.CellEditingTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
</my:DataGrid>
and my Test was:
[Test]
public void TestDatagrid5()
{
var tab = _win.Get<ListView>(SearchCriteria.ByAutomationId("dataGrid1"));
var count = tab.Rows.Count;
var row = tab.Rows[1];
ListViewCell x = row.Cells[1]; //Always count = 0 :(
}
but the cell count is always = 0, I need to get cell value !!!? any help please!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不喜欢这个答案,并且想找到更好的方法来做到这一点。
也就是说,如果您向 ListViewRow 项询问网格中的元素,您可以使用 UiAutomationElement 并自己创建该元素的白色版本。
I don't like this answer and would like to find a better way of doing this..
That said if you ask the ListViewRow item for the element in your grid you can then take the UiAutomationElement and create the White version of that element your self.
此方法可能不适用于仅获取可见的所有行
As a warning this method may not work for getting all the rows just the ones visible
我建议另一种方法。如果网格支持导出到 CSV - 请改用它。这将为您节省几个月的工作!如果我之前知道这一点就好了……
识别细胞和提取值可能会很痛苦。许多网格控件都进行 UI 虚拟化。不适合视口的单元格将不会被创建。您必须滚动网格才能强制渲染它们。
我个人使用 DevExpress 网格。他们的 CSV 导出保留了格式,因此您将获得与屏幕上显示的值完全相同的值!
I'd suggest another way around. If the grid supports export to CSV - use it instead. That will save you man months of work! If only I knew that before...
Identifying cells and extracting values can be painful. Many grid controls do UI virtualization. The cells which do not fit the viewport won't be created. You'll have to scroll the grid to force their rendering.
Personally I use the DevExpress grid. Their CSV export preserves the formatting, so you'll get the values exactly as they appear on the screen!