0

so if I want to get/set the window size, everyone brings up left, top, actualLeft, actualTop. And if I want to get/set window location, everyone brings up LocationChanged event.

But I have none of these. I am on a WPF Page and I only see SizeChanged event. I want to get/set width and height and also get/set the window location.

I have this structure:

<Page
    <!-- stuff here -->
   SizeChanged="Page_SizeChanged" Loaded="Page_Loaded">

    <Grid Width="auto" Height="auto">

    </Grid>
</Page>

And in code behind (MyPage.xaml.cs), if I use this.width, the grid width changes but not the window width. And there is no top, left properties or LocationChanged events.

How can I do that?

Sandra K
  • 1,209
  • 1
  • 10
  • 21
  • 1
    The `Page` WPF element is meant to be a container displayed in a navigation window or web browser. It inherits the container size. If you want to set the container's size, you need to get the current page's container and somehow set it's size. This is much easier to do following an MVVM pattern than code-behind, because the container VM can know about the page VM and subscribe to some kind of resizing event or properties. – Ron Beyer Mar 22 '18 at 19:33
  • Alternatively if you are developing on the desktop, just use the `Window` instead of `Page`. – Ron Beyer Mar 22 '18 at 19:34
  • @RonBeyer I can not redo the app and use a `Window`. But it is a MVVM on Desktop. Can you please show me how to do it from the VM? – Sandra K Mar 22 '18 at 19:43
  • What is hosting the page? A web-browser? – Ron Beyer Mar 22 '18 at 19:44
  • The page VM would have some properties for the Width/Height/Top/Left that the Window VM would subscribe to. The Window VM can then have bindable properties for those that you bind the view to. – Ron Beyer Mar 22 '18 at 19:49
  • I did not get it ... – Sandra K Mar 22 '18 at 20:14

0 Answers0