C# WPF how to set location,width and height of the controls programmatically?

后端 未结 6 1274
慢半拍i
慢半拍i 2021-01-01 23:14

I\'m doing my first WPF application. im having problem whereby when my form is maximized or fullscreen, my controls wont resize and just stay in the same location. only the

6条回答
  •  余生分开走
    2021-01-01 23:23

    Use some calculations like (control's previous position * layout's new size) / layout's previous size = control's new position

    But the easiest way is to use XAML Use Grid and put columns and rows in it and set the size of columns and rows to * So on layout size change, your controls will reposition in refer to parent's change in size which your grid is child of it. And you could even have auto resizable controls just by setting the controls' margins in columns and rows. Don't forget horizontal and vertical alignments set to stretch.

提交回复
热议问题