-1

I have a popup window that appears which can change its width/height based on user actions. When the window opens it initially opens centred. However, when the dimensions change, they scale from the top left corner as the fixed point. How can I expand from the centre? I'd prefer to do this from XAML Definition if possible.

Harry Adams
  • 423
  • 5
  • 16

2 Answers2

1

Rather than changing the window size I suggest you instead consider changing the content size.

Which will probably be easier.

By content, I mean whatever you show inside this window.

Make the window style = none and allowstransparent=true.

Give it a background of x:null.

Put a grid in it with a null background similarly.

Then put your content inside that and change the height and width of the content. Put a border round the content so it looks like an obvious panel/window.

By default when you put something with a specific width and height in it, the grid will centre it's/your content.

You won't be able to see anything or click on anything where the window is but the content is not.

Andy
  • 11,864
  • 2
  • 17
  • 20
0

You should be able to set the startup position, if you want it to do it from the center then you will probably have to do it in the C# code behind and do a calculation to move it half of the window width to the left, or something like that. Experiment with values and find what works for you.

Here is a post about setting the window startup location: https://stackoverflow.com/a/1545278/8306962

Issung
  • 385
  • 3
  • 14