Can anyone explain the difference between using:
GridLength length = new GridLength(0, GridUnitType.Auto)
and
GridLength length = new GridLength(1, GridUnitType.Auto)
My limited knowledge of this leads me to believing these would both be identical solutions due to auto being as it states..."auto", therefore making the double value redundant.
Most examples I have seen show the GridUnitType.Auto
being preceded with 1 rather than 0, but it seems to me that either option works the same?
Is this the case or can anyone shed some light on if/how these are different
I think your understanding is correct, when the value
GridUnitType.Auto
is used, the first value passed to the constructor is redundant, as the size will be determined by the content object.It somewhat makes sense in the context of the
GridLength
structure constructor to retain this parameter (even though it's not used in this instance), as it allows the second parameter type to contain values that describe the all available states ofGridUnitType
.From the documentation:
The enumerated type
GridUnitType
can contain the following values:So really, the first parameter is only relevant when the second parameter is set to
GridUnitType.Pixel
orGridUnitType.Star
.It wouldn't work neatly other way around e.g. if you tried to have constructor that accepted 1 parameter as a
GridUnitType
, and only required the second parameter if you usedPixel
orStar
.This way round, you get the benefit of having a 1 parameter constructor that accepts a double without specifying the additional type. Although it does have the cost of a potentially odd looking two parameter constructor when using
Auto
(as in your example).