C # WPF - GridLength GridUnitType.Auto

Can someone explain the difference between usage:

GridLength length = new GridLength(0, GridUnitType.Auto) 

and

  GridLength length = new GridLength(1, GridUnitType.Auto) 

My limited knowledge of this leads me to think that they will be identical solutions due to automatic presence, as it declares ... "auto", therefore making a double value redundant.

Most of the examples I've seen show that GridUnitType.Auto preceded by 1, not 0, but it seems to me that any option works the same?

In this case, or can someone shed light if / how they differ

+7
c # wpf
source share
1 answer

I think your understanding is correct when using the value of GridUnitType.Auto , the first value passed to the constructor is redundant, as the size will be determined by the content object.

In the context of the GridLength structure constructor, it GridLength some sense to save this parameter (even if it is not used in this instance), since it allows the second type of parameters to contain values ​​that describe all available states of GridUnitType .

In the documentation:

The enumerated type GridUnitType may contain the following values:

 Auto - The size is determined by the size properties of the content object. Pixel - The value is expressed as a pixel. Star - The value is expressed as a weighted proportion of available space. 

So, the first parameter is applicable only when the second parameter is set to GridUnitType.Pixel or GridUnitType.Star .

It would not work neatly in another way, for example. if you tried to create a constructor that took 1 parameter as GridUnitType , and only the second parameter was required if you used Pixel or Star .

Thus, you get the benefit of the designer with 1 parameter, which takes a double, without specifying the additional type. Although using Auto (as in your example), it has the potential costs of an odd kind of two constructors parameters.

+14
source share

All Articles