C#後台動態添加Grid表格

來源:互聯網
上載者:User

標籤:erb   llb   media   windows   gif   頁面   sed   closed   log   

前面頁面:

1 <ScrollViewer x:Name="sv_data" Grid.Row="1" BorderBrush="#25A0DA" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">2 3 <Grid x:Name="rgv_schedule" Background="White" Width="3150"></Grid>4 5 </ScrollViewer>
View Code

 

從後台動態添加行和列

添加多行:

1                 //建立5行2                 for (int k = 0; k < 5; k++)3                 {4                     RowDefinition row = new RowDefinition() { Height = new GridLength(30) };5                     grid_box.RowDefinitions.Add(row);6                 }
View Code

 

添加列:

 1             //清空列表 2             rgv_schedule.Children.Clear(); 3             //添加第一行(表頭) 4             RowDefinition row = new RowDefinition() { Height = new GridLength(30) }; 5             rgv_schedule.RowDefinitions.Add(row); 6             //姓名列 7             ColumnDefinition col_name = new ColumnDefinition() { Width = new GridLength(50) }; 8             rgv_schedule.ColumnDefinitions.Add(col_name); 9 10             System.Windows.Controls.Border b_name = new System.Windows.Controls.Border() { BorderThickness = new Thickness(1, 1, 1, 1), BorderBrush = new SolidColorBrush(System.Windows.Media.Colors.Black) };11             TextBlock txt_name = new TextBlock() { Text = "姓名", FontSize = 13, FontWeight = FontWeights.Black, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Center };12             b_name.Child = txt_name;13             b_name.SetValue(Grid.ColumnProperty, 0);//設定邊框所在列14             b_name.SetValue(Grid.RowProperty, 0);//設定邊框所在行15             rgv_schedule.Children.Add(b_name);//將邊框添加到表格中
View Code

 

C#後台動態添加Grid表格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.