Reputation: 15658
In visual studio, when dragging a control from the toolbox onto the design area, VS automatic sets width and height of the control with some values. Do you know how it does it? I was suspicious that there were some kind of attributes for the Width and Height properties or even the class itself but could not find anything from reflecting the Button control.
Upvotes: 2
Views: 138
Reputation: 967
Actually, there is no any magic, the VS would need to do to acquire those defaults. My guess, it allows all layout passes to finish and then simply copies values of ActualWidth
and ActualHeight
properties.
Google a little on the purpose of MeasureOverride
and ArrangeOverride
methods, layout passes, etcetera.
Have in mind, that actual default values for dependency properties are specified by their metadata either along with their registration or by means of overriding it in subclasses. I believe, that actual default value for either of Width
and Height
properties is the double.NaN
value.
Upvotes: 1
Reputation: 23935
I haven't found it using reflector yet, at least not in the Button class. When i add a button using xaml, it will take up the available space given to it. when i add one using the designer, its height gets set at 23.
this article describes creating a control with default values for use in the toolbox, i would assume that the toolbox items are done the same way.
Upvotes: 0