Silverlight DataGrid模板列的动态生成

来源:转载

 string strXaml = @" <DataTemplate xmlns='http://schemas.microsoft.com/client/2007'>            <Grid HorizontalAlignment='Center' VerticalAlignment='Center'>
                <Grid.RowDefinitions>
                    <RowDefinition Height='35'></RowDefinition>
                    <RowDefinition Height='35'></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width='150'></ColumnDefinition>
                    <ColumnDefinition Width='150'></ColumnDefinition>
                </Grid.ColumnDefinitions>
                    <TextBlock Text='Col1'></TextBlock>
                    <TextBlock Text='Col2' Grid.Column='1'></TextBlock>
                {0}
            </Grid>
                </DataTemplate>";


            StringBuilder sb = new StringBuilder();
            int k = 0;
            foreach (var item in this.objTableCaseTemplate.lstDBCaseItemTemplate)
            {
                if (k >= 2) break;
                string tbn = "DB_" + item.PhyTbName;
                string s = item.ItemName;
                sb.AppendLine("<TextBox Text='{Binding Path=" + tbn + "." + s + ",Mode=TwoWay }' Grid.Column='" + 
k + "' Grid.Row='1'/>");
                k++;
            }

            strXaml = string.Format(strXaml, sb.ToString());

            DataTemplate dtTemplate = (DataTemplate)XamlReader.Load(strXaml);

            DataGridTemplateColumn tmpCol = new DataGridTemplateColumn();
            tmpCol.Header = "某个组";
            tmpCol.CellTemplate = dtTemplate;
            this.dataGridCaseList.Columns.Add(tmpCol);

本文来自InFuture的博客,原文地址:http://www.cnblogs.com/futureflare/archive/2011/06/20/2085408.html


分享给朋友:
您可能感兴趣的文章:
随机阅读: