【问题标题】:Nested columns in silverlight datagrid, nested datagridsilverlight 数据网格中的嵌套列,嵌套数据网格
【发布时间】:2011-11-18 19:47:48
【问题描述】:

我想创建具有嵌套列的数据网格(请查看附图)。或者如果可能的话,将网格嵌入到单元格中。 我的对象有许多不同的信息,根据对象类型,我想在我的单元格中添加其他信息(图像中的嵌套列),按列划分。在silverlight中可以吗?

如果可能的话,将整个新网格插入单元格是完美的。

TIA 有任何建议

【问题讨论】:

    标签: c# silverlight silverlight-4.0 datagrid


    【解决方案1】:

    利用数据网格的 LoadingRow 事件,根据数据上下文分配适当的数据模板。

    与我的回复类似:

    Enabling/Disabling row in a data grid

    您执行以下操作:

    private void MyDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
    {
        MyDataObjectClass dataContext = (e.Row.DataContext as MyDataObjectClass);
    
        foreach (DataGridColumn col in from cols in MyDataGrid.Columns orderby cols.DisplayIndex select cols)
        {
            FrameworkElement fe = col.GetCellContent(e.Row);
    
            DataGridCell result = fe.Parent as DataGridCell;
    
            // as an example, find a template column w/ a desired sort member path
            if (col is DataGridTemplateColumn && col.SortMemberPath == "x")
            {
                if (condition1)
                {
                    result.ContentTemplate = (DataTemplate)Resources["NestedGridTemplate1"];
                }
                else 
                {
                    result.ContentTemplate = (DataTemplate)Resources["NestedGridTemplate2"];
                }                   
            }
        }
    }
    

    【讨论】:

      【解决方案2】:

      对不起,我读了“网格”8-)

      对于数据网格,您可以使用数据模板来完成。

      http://mscoder.wordpress.com/2010/09/11/nested-datagrid-using-silverlight-4-and-wcf/

      【讨论】:

      • 我要求 datagrid 解决方案 :) 没有布局网格。
      • 对不起,我希望这个可以帮助你;-)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      • 2010-10-06
      • 1970-01-01
      • 2014-05-03
      • 2011-02-25
      相关资源
      最近更新 更多