【发布时间】:2012-07-17 08:05:24
【问题描述】:
这里很简单。 我创建了一个数据网格,它有一组行。我想隐藏特定行 行加载后是否基于特定逻辑?
有什么想法吗?
【问题讨论】:
标签: data-binding silverlight-4.0 datagrid visibility
这里很简单。 我创建了一个数据网格,它有一组行。我想隐藏特定行 行加载后是否基于特定逻辑?
有什么想法吗?
【问题讨论】:
标签: data-binding silverlight-4.0 datagrid visibility
代码需要调整,但我正在寻找解决方案,并认为值得发布。
Private Sub gridComments_LoadingRow(sender As Object, e As DataGridRowEventArgs) Handles gridComments.LoadingRow
Dim row As DataGridRow = e.Row
For Each col As DataGridColumn In gridComments.Columns
Dim g1 As FrameworkElement = col.GetCellContent(e.Row)
Dim c As UIElement = g1.FindName("ChildElementName")
c.Opacity = 0 'Change the desired properties here
Next
End Sub
private void gridComments_LoadingRow(object sender, DataGridRowEventArgs e)
{
DataGridRow row = e.Row;
foreach (DataGridColumn col in gridComments.Columns) {
FrameworkElement g1 = col.GetCellContent(e.Row);
UIElement c = g1.FindName("ChildElementName");
c.Opacity = 0;
//Change the desired properties here
}
}
有点晚了,但这对我有用。
【讨论】:
在行加载事件上,即 LoadingRow,因此在每行加载时,您都会获得 DataGridRow,其中您有数据上下文。让我们说人(id,名字)
这就是你可以玩的方式..
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;
}
}
}
【讨论】: