How does Visual Studio size WPF controls?

In visual studio, when you drag a control from the toolbar to the design area, VS will automatically set the width and height of the control with some values. Do you know how it goes? I was suspicious that there were some attributes for the Width and Height properties or even the class itself, but couldn't find anything from the reflection of the Button control.

+2


source to share


2 answers


In fact, there is no magic VS will have to do to get these defaults. My guess is that it lets you complete all layouts and then just copies the values ​​of the properties ActualWidth

and ActualHeight

.

Google a little with the aim of methods MeasureOverride

and ArrangeOverride

, layouts passes, etc.



Be aware that the actual defaults for dependency properties are determined by their metadata, either along with their registration, or by overriding them in subclasses. I believe the actual default for any of the properties is Width

and Height

is the value double.NaN

.

+1


source


I haven't found it with a reflector yet, at least not in the Button class. When I add the button using xaml it will take up the available space given to it. when I add one using the constructor its height is set to 23.



this article describes how to create a control with default values ​​for use in the toolbar, I would assume the toolbar items perform the same way.

0


source







All Articles