I have written the following code to create a fixed document.
On the page I add a stack panel. The stack panel contains some textblocks and a grid. The grid is supposed to have three columns: 10%, 45% and 45%.
However the Grid goes off the page but I don't know why. Any suggestions?
FixedDocument fd = new FixedDocument();
Grid grd = new Grid();
grd.ShowGridLines = true;
grd.HorizontalAlignment = HorizontalAlignment.Stretch;
RowDefinition row_def;
ColumnDefinition col_def;
col_def = new ColumnDefinition();
col_def.Width = new GridLength(0.1, GridUnitType.Star);
grd.ColumnDefinitions.Add(col_def);
col_def = new ColumnDefinition();
col_def.Width = new GridLength(0.45, GridUnitType.Star);
grd.ColumnDefinitions.Add(col_def);
col_def = new ColumnDefinition();
col_def.Width = new GridLength(0.45, GridUnitType.Star);
grd.ColumnDefinitions.Add(col_def);
...
StackPanel sp = new StackPanel();
sp.Margin = new Thickness(32, 20, 20, 20);
sp.Children.Add(grd);
...
Size pgSize = new Size(96 * 8.27, 96 * 11.69);
FixedPage fp = new FixedPage();
fp.Width = pgSize.Width;
fp.Height = pgSize.Height;
fp.Children.Add(sp);
PageContent pc = new PageContent();
pc.Child = fp;
fd.Pages.Add(pc);
I tried adding just the grid to the stack panel, just the grid by itself with no stack panel, and I also tried using these values for GridLenth but it made no difference:
col_def = new ColumnDefinition();
col_def.Width = new GridLength(10, GridUnitType.Star);
grd.ColumnDefinitions.Add(col_def);
col_def = new ColumnDefinition();
col_def.Width = new GridLength(45, GridUnitType.Star);
grd.ColumnDefinitions.Add(col_def);
col_def = new ColumnDefinition();
col_def.Width = new GridLength(45, GridUnitType.Star);
grd.ColumnDefinitions.Add(col_def);