Redaa
Redaa

Reputation: 1590

what is correct place to initialize width/height of a WPF control

am a beginner and until now I've been re-sizing my control in the VS designer, i wonder what is the correct place to initialize a control property.

Upvotes: 0

Views: 564

Answers (1)

Breealzibub
Breealzibub

Reputation: 8095

Usually you want your user interface controls to automatically resize with the parent Window, for instance when the user resizes the window. In this case, you don't want to specify a hard and fast width/height in your code or in the VS designer. You would instead place the user control inside of one of the appropriate layout controls available in WPF.

There are, however, some times when you want your user control to be one size and always one size. In this case, you would assign it in one of two places:

  1. If it's just a single control, then you would specify the "Height" and "Width" properties in your XAML for that control: <UserControl Width="100" Height="100" />
  2. If it's a size that might be reused in multiple copies of a user control, then you may want to specify the Width and Height properties inside of a common Style.

Upvotes: 2

Related Questions