有兩種辦法:
1. 直接在後臺處理
在數據綁定後 ,註冊LoadingRow 事件
this.DataGrid.LoadingRow += new EventHandler<DataGridRowEventArgs>(DataGrid_LoadingRow);
web
void DataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
Task ts = e.Row.DataContext as Task;
ToolTipService.SetToolTip(e.Row, ts.Name);
//throw new NotImplementedException();
}
2. 稍微麻煩點, 重寫datagrid row 模板,
在微軟msdn 上能找到 行模板,找到
<Storyboard>
<DoubleAnimation Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" Duration="0" To="0"/>
</Storyboard>
在後面加上
<Storyboard>
<DoubleAnimation Storyboard.TargetName="BackgroundRectangle" Storyboard.TargetProperty="Opacity" Duration="0" To="0"
ToolTipService.ToolTip="{Binding Name}"/> </Storyboard>