wpf利⽤后台⽣成grid表格以及tabcontrol,border等⽤法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);
borderboxbor.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);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。