question

EmonHaque-1485 avatar image
0 Votes"
EmonHaque-1485 asked EmonHaque-1485 answered

How to position items in FixedPage?

In the constructor of my LedgerPage, I've this:

 Page = new FixedPage() {
     Width = PageSize.Width,
     Height = PageSize.Height,
     Margin = new Thickness(margin),
     Children = { header, content, footer }
 };

and after some property change, I call measure and this is what I've to position items in the Page:

 void measure() {
     var availableSize = new Size(PageSize.Width - 2 * margin, PageSize.Height - 2 * margin);
     ...
     double y = 0;
     foreach (FrameworkElement item in Page.Children) {
         item.Width = availableSize.Width;
         item.Measure(availableSize);
         item.Arrange(new Rect(new Point(margin, y), item.DesiredSize));
         y += item.DesiredSize.Height;
     }
     ...
 }

BUT it positions all three items in same place so they overlap:

98844-test.gif

In the previous version of this app, I'd one Grid as the Children of Page and in that I put header, content and footer. Now, I want to get rid of that and position each item in the FixedPage, how to do that?

windows-wpf
test.gif (353.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

EmonHaque-1485 avatar image
0 Votes"
EmonHaque-1485 answered

This was helpful, all that I needed was FixedPage.SetTop(...):

 foreach (FrameworkElement item in Page.Children) {
     item.Width = availableSize.Width;
     item.Measure(availableSize);
     FixedPage.SetTop(item, y);
     y += item.DesiredSize.Height;
 }

I don't have to call Measure/Arrange/UpdateLayout on the Page.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.