这里很简单。 我创建了一个数据网格,其中有一组行。我想隐藏特定行 基于行加载后的特定逻辑?
有什么想法吗?
最佳答案
在行加载事件(即 LoadingRow)上,因此在每行加载时您都会获得 DataGridRow,其中包含数据上下文。可以说 Person (id, name)
这就是你可以玩的方式..
private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
{
if(e.Row != null)
{
var row = e.Row.DataContext;
var person = row as Person;
if (person != null && person.Id == 2)
{
(e.Row as DataGridRow).IsEnabled = false;
}
if (person != null && person.Id == 1)
{
(e.Row as DataGridRow).Visibility = Visibility.Collapsed;
}
}
}
关于data-binding - 如何在 row_loading 事件之后隐藏 silverlight datagrid 行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11538807/