【问题标题】:silverlight build a datagrid in the code behindsilverlight 在后面的代码中构建数据网格
【发布时间】:2012-10-31 12:05:01
【问题描述】:

Silverlight DataGrid 中是否可以有一列包含具有不同类型控件的行?例如,列的前两行应该是文本,接下来的两行将有按钮,然后接下来的 6 行将有复选框。我还需要在后面的代码中构建它。任何帮助,将不胜感激。

【问题讨论】:

  • 感谢大家的回复。结果我使用了一个 Flex Grid 组件来完成我需要的工作。

标签: silverlight datagrid


【解决方案1】:

也许代码下面的代码给了你这个想法。

        foreach (var item in ItemList)
        {
            //Row definition and column definitions are similar
            LayoutRoot.RowDefinitions.Add(new RowDefinition() 
            { Height = GridLength.Auto});         

            HelloObject hl=new HelloPObject();

            //Attached property imeplemantation
            Grid.SetRow(hl,Layout2.RowDefinitions.Count);

            //You may add any UIElement as Children
            LayoutRoot.Children.Add(hl);                
        }

编辑:对不起,我没有意识到数据网格。

好吧,它也可能用于数据网格, AFAIK Telerik 的 radgridview 为您提供行的索引。但您可以自己管理。

除此之外,当您点击网格排序时,此顺序可能会丢失,具体取决于列的排序成员路径。但您可以根据 DataGrid 的 ItemsSource 元素中的属性切换 CellTemplate。

 DataGrid grid = new DataGrid();
        int rowNdx = 0;
        grid.LoadingRow += (s, a) =>
            {                    
                DataGridCell cell = myList.Columns[0].GetCellContent(a.Row).Parent as DataGridCell;
                switch (rowNdx)
                {
                    case 0:
                        cell.Content = new TextBlock() { Text= "Click" };
                        break;
                    default:
                        cell.Content = new Button() { Content = "Click" };                    
                        break;
                }
                rowNdx++;                    
            };

【讨论】:

  • 这可能对我有用,但我确实有一个问题。是否可以在后面代码中的数据网格中执行此操作?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-19
  • 2016-07-23
  • 2017-08-13
相关资源
最近更新 更多