When defining custom resource themes for a wpf application, I can set width / height etc... How can I find the default value for these properties (i.e. the values used in the controls provided in the framework) ?
相关问题
- VNC control for WPF application
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
- How to properly change a resource dictionary
WPF controls don't generally contain any kind of default size. One of the main functional points of WPF is that everything resizes dynamically unless you specify a size.
If you do want to measure the amount of space a control would like to have if given infinite space, you can create it, call Measure on it with a Size of +infinity, +infinity, and then check DesiredSize. For most controls, this will give you the minimum size the control wants. If you give a fixed size in Measure, some controls will return that they want all that space as they size to their container (e.g., Grid, TextBox, Button...). Some controls size only to their content, so they'll tell you they want no space (e.g., StackPanel).
So you have to ask yourself why you would even think of the concept of a default size in WPF when almost all controls are made so that they either size to their content or size to their container depending on how they are set up. The main thing you'd want to measure is text, and you can do that with the trick above for items like TextBlock or images.
Edit: to query any DependencyProperty for a default value, use the property's metadata:
To Reset a DependencyProperty to its default value, call DependencyObject's ClearValue:
To check for a locally set value:
The default width and height for FrameworkElements is
Double.NaN
. If you don't specify a different size then WPF controls will automatically size themselves to try and fit their content, their containers or both.