wpf利用后台生成grid表格以及tabcontrol,border等用法

来源:互联网 发布:玄幻小说 知乎 编辑:程序博客网 时间:2024/06/03 22:42

wpf利用后台生成grid表格以及tabcontrol,border等用法

 

TabControl tabCtrol = new TabControl();            int count = 0;            if (listPath.Count % 25 == 0)            {                count = listPath.Count / 25;            }            else            {                count = listPath.Count / 25 + 1;            }            for (int k = 0; k < count; k++)            {                TabItem tabItem = new TabItem();                tabItem.Header = "第" + k + "页";                Grid gridItem = new Grid();                for (int i = 0; i < 5; i++)                {                    //创建行                    RowDefinition row = new RowDefinition();                    gridItem.RowDefinitions.Add(row);                    //创建列                    ColumnDefinition column = new ColumnDefinition();                    gridItem.ColumnDefinitions.Add(column);                }                for (int i = 0; i < 5; i++)                {                    for (int j = 0; j < 5; j++)                    {                        if ((j + i * 5 + k * 25) < listPath.Count)                        {                            Border bor = new Border();                            bor.BorderBrush = new SolidColorBrush(Colors.Red);                            bor.BorderThickness = new Thickness(1);                            //bor.Tag = "hollo";                            //bor.CornerRadius = new CornerRadius(12);                            //bor.Background = new SolidColorBrush(Colors.Yellow);                            FrameworkElement viewBox = readXaml(listPath[j + i * 5 + k * 25]);                                                        TextBlock tb = new TextBlock();                            tb.Text = listName[j + i * 5 + k * 25];                            StackPanel panel = new StackPanel();                            panel.Children.Add(tb);                            panel.Children.Add(viewBox);                            bor.Child = panel;                            Grid.SetColumn(bor, j);                            Grid.SetRow(bor, i);                            gridItem.Children.Add(bor);                        }                    }                }                tabItem.Content = gridItem;                tabCtrol.Items.Add(tabItem);            }                        grid.Children.Add(tabCtrol);


 

原创粉丝点击