【问题标题】:How do I hide a silverlight datagrid row after the row_loading event?如何在 row_loading 事件之后隐藏 silverlight 数据网格行?
【发布时间】:2012-07-17 08:05:24
【问题描述】:

这里很简单。 我创建了一个数据网格,它有一组行。我想隐藏特定行 行加载后是否基于特定逻辑?

有什么想法吗?

【问题讨论】:

    标签: data-binding silverlight-4.0 datagrid visibility


    【解决方案1】:

    代码需要调整,但我正在寻找解决方案,并认为值得发布。

    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
        }
    }
    

    有点晚了,但这对我有用。

    【讨论】:

      【解决方案2】:

      在行加载事件上,即 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;
                  }
              }
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-03
        • 2018-07-19
        • 2014-05-31
        • 1970-01-01
        • 1970-01-01
        • 2013-08-17
        • 2013-10-19
        • 2016-01-23
        相关资源
        最近更新 更多