1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
private static void ReArrangePage(Panel parent)
{
UIElement item;
_pageRoot = new StackPanel { Orientation = Orientation.Vertical, VerticalAlignment = System.Windows.VerticalAlignment.Stretch };
foreach (UIElement ele in parent.Children)
{
if (ele is Panel)
{
switch (ele.GetType().Name)
{
case "Grid":
{
item = new Grid { Height = ele.DesiredSize.Height };
foreach (UIElement child in (ele as Panel).Children)
(item as Grid).Children.Add(AddChildren(child));
break;
}
case "StackPanel":
{
item = new StackPanel { Height = ele.DesiredSize.Height };
foreach (UIElement child in (ele as Panel).Children)
(item as StackPanel).Children.Add(AddChildren(child));
break;
}
default:
{
item = new TextBlock {Text = ele.GetType().Name + " type is not implemented yet for data printing"};
break;
}
}
_pageRoot.Children.Add(item);
}
else if (ele is ItemsControl)
{
switch (ele.GetType().Name)
{
case "ListBox":
{
item = new ListBox { Height = ele.DesiredSize.Height };
foreach (UIElement child in (ele as ListBox).Items)
(item as ListBox).Items.Add(AddChildren(child));
break;
}
default:
{
item = new TextBlock { Text = ele.GetType().Name + " type is not implemented yet for data printing" };
break;
}
}
_pageRoot.Children.Add(item);
}
else if (ele is DataGrid)
{
double height = 0;
foreach (DataGridRow r in (ele as DataGrid).GetRows())
height += r.Height;
height += (ele as DataGrid).ColumnHeaderHeight;
item = new DataGrid { Height = height, ItemsSource = (ele as DataGrid).ItemsSource };
_pageRoot.Children.Add(item);
}
else
{
switch (ele.GetType().Name)
{
case "TextBox":
item = new TextBox { Text = (ele as TextBox).Text, Width = (ele as TextBox).Width };
break;
case "RadioButton":
item = new RadioButton { Content = (ele as RadioButton).Content, IsChecked = (ele as RadioButton).IsChecked, Width = (ele as RadioButton).Width };
break;
case "CheckBox":
item = new CheckBox { Content = (ele as CheckBox).Content, IsChecked = (ele as CheckBox).IsChecked, Width = (ele as CheckBox).Width };
break;
case "TextBlock":
item = new TextBlock { Text = (ele as TextBlock).Text, Width = (ele as TextBlock).Width };
break;
case "Button":
item = new Button { Content = (ele as Button).Content, Width = (ele as Button).Width };
break;
default:
item = new TextBlock { Text = ele.GetType().Name + " type is not implemented yet for data printing" };
break;
}
_pageRoot.Children.Add(item);
}
}
} |
Partager