您好,
>>获取DataGrid中内容,可以参考下面的代码:
C# Code:
private void GetDataGridContent()
{
DataGridCell cell = GetCell(4, 1);
TextBlock tb = cell.Content as TextBlock;
MessageBox.Show(tb.Text);
//....
}
public DataGridCell GetCell(int row, int column)
{
DataGridRow rowContainer = GetRow(row);
if (rowContainer != null)
{
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
if (cell == null)
{
dataGrid1.ScrollIntoView(rowContainer, dataGrid1.Columns[column]);
cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
}
return cell;
}
return null;
}
public DataGridRow GetRow(int index)
{
DataGridRow row = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(index);
if (row == null)
{
dataGrid1.UpdateLayout();
dataGrid1.ScrollIntoView(dataGrid1.Items[index]);
row = (DataGridRow)dataGrid1.ItemContainerGenerator.ContainerFromIndex(index);
}
return row;
}
public static T GetVisualChild<T>(Visual parent) where T : Visual
{
T child = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
child = v as T;
if (child == null)
{
child = GetVisualChild<T>(v);
}
if (child != null)
{
break;
}
}
return child;
}
>>在DataGrid中指定位置添加Button。
我建议您这样来操作,先将这个Button放在指定位置,隐藏掉。当满足您的条件时,再将它显示。这样比较好做些。
祝您生活愉快!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.