How to position items in FixedPage?

Emon Haque 3,176 Reputation points
2021-05-23T04:40:54.953+00:00

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 Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,624 questions
0 comments No comments
{count} votes

Accepted answer
  1. Emon Haque 3,176 Reputation points
    2021-05-23T05:25:50.653+00:00

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful