public void Getcell ()
{
for (int i = 0; i < This.datagrid1.Items.Count; i++)
{
DataRowView DRV = DataGrid1. Items[i] as DataRowView;
DataGridRow row = (datagridrow) this.datagrid1.ItemContainerGenerator.ContainerFromIndex (i);
if (i = = 1)//If the line number equals 1
{
Datagridcellspresenter presenter = getvisualchild<datagridcellspresenter> (row);
DataGridCell cell = (DataGridCell) presenter. Itemcontainergenerator.containerfromindex (1);//Get Column number 1
Cell. Background = new SolidColorBrush (colors.red);
ToolTip tip=new tooltip ();
tip.context= "1234";
Cell. Tooltip=tip;
}
}
}
public static T getvisualchild<t> (Visual parent) where t:visual
{
T childcontent = default (t);
int numvisuals = Visualtreehelper.getchildrencount (parent);
for (int i = 0; i < numvisuals; i++)
{
Visual V = (visual) visualtreehelper.getchild (parent, I);
Childcontent = v as T;
if (childcontent = = null)
{
Childcontent = getvisualchild<t> (v);
}
if (childcontent! = null)
{
Break
}
}
return childcontent;
}
Prevents an error in fetching the row of the DataGrid, which is called in the Window_Loaded event
public void loed ()
{
if (! Window.getwindow (DATAGRID1). IsVisible)
{
Window.getwindow (DATAGRID1). Show ();
}
Datagrid1.updatelayout ();
}
WPF gets a DataGrid cell that sets the tooltip content and background color for this cell